mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-29 20:43:58 +01:00
Compare commits
No commits in common. "d1e29735be888aa18237c8124251fa0f43add96f" and "f535aab1ebcbb03cde882bd92d04d18903072bac" have entirely different histories.
d1e29735be
...
f535aab1eb
@ -38,12 +38,6 @@ this repo: describe what changes for them. 0.0.1 shipped a bullet about
|
|||||||
`/healthz`, an endpoint bound to 127.0.0.1 that nobody in a Signal group can
|
`/healthz`, an endpoint bound to 127.0.0.1 that nobody in a Signal group can
|
||||||
reach, and it was rightly called out.
|
reach, and it was rightly called out.
|
||||||
|
|
||||||
## 0.1.2 — Anicet
|
|
||||||
|
|
||||||
- `!ja` pokazywał wszystkim tę samą godzinę (12:00) — to był artefakt
|
|
||||||
danych sprzed przebudowy licznika, a nie wasze zwyczaje. Teraz pokazuje
|
|
||||||
prawdziwe godziny, a komu ich nie znamy, temu nie zmyśla
|
|
||||||
|
|
||||||
## 0.1.1 — Pius I
|
## 0.1.1 — Pius I
|
||||||
|
|
||||||
- komendy mówią teraz, co pokazują — `!korona` na pustych danych tłumaczy,
|
- komendy mówią teraz, co pokazują — `!korona` na pustych danych tłumaczy,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "signal-bot"
|
name = "signal-bot"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
description = "A Signal group bot: image commands and daily message tallies."
|
description = "A Signal group bot: image commands and daily message tallies."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@ -28,16 +28,10 @@ if TYPE_CHECKING:
|
|||||||
from signal_bot.store import Store
|
from signal_bot.store import Store
|
||||||
|
|
||||||
BACKFILL_KEY: Final = "backfill_day"
|
BACKFILL_KEY: Final = "backfill_day"
|
||||||
# -1, because a backfilled event has no hour at all and any value in 0..23 is
|
# Noon: a backfilled event has no real hour, and midnight would look like a
|
||||||
# a lie that reads as data. This started as 12, on the reasoning that the day
|
# deliberate reading rather than an absent one. The day is marked anyway, so
|
||||||
# is marked so "nothing that cares about hours will read these" -- and then
|
# nothing that cares about hours will read these.
|
||||||
# favourite_hour did, and told all seven people their favourite hour was
|
BACKFILL_HOUR: Final = 12
|
||||||
# 12:00, because 319 synthetic noons outweighed every real evening.
|
|
||||||
#
|
|
||||||
# The lesson is in the type, not in a comment: an absent value must not be
|
|
||||||
# spellable as a present one. Hour queries filter `local_hour >= 0`, so
|
|
||||||
# forgetting to exclude the backfilled day can no longer invent an answer.
|
|
||||||
UNKNOWN_HOUR: Final = -1
|
|
||||||
|
|
||||||
|
|
||||||
def has_legacy_counter(store: Store) -> bool:
|
def has_legacy_counter(store: Store) -> bool:
|
||||||
@ -83,7 +77,7 @@ def seed_from_counter(store: Store, day: str) -> dict[str, int]:
|
|||||||
display_name=row["display_name"],
|
display_name=row["display_name"],
|
||||||
sent_at_ms=index + 1,
|
sent_at_ms=index + 1,
|
||||||
day=day,
|
day=day,
|
||||||
local_hour=UNKNOWN_HOUR,
|
local_hour=BACKFILL_HOUR,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
store.events.note_person(group_id, row["uuid"], row["display_name"], "", day)
|
store.events.note_person(group_id, row["uuid"], row["display_name"], "", day)
|
||||||
|
|||||||
@ -198,7 +198,6 @@ def night_owl(facts: DayFacts) -> Highlight | None:
|
|||||||
SELECT display_name, local_hour
|
SELECT display_name, local_hour
|
||||||
FROM message_events
|
FROM message_events
|
||||||
WHERE group_id = ? AND day = ? AND local_hour BETWEEN ? AND ?
|
WHERE group_id = ? AND day = ? AND local_hour BETWEEN ? AND ?
|
||||||
AND local_hour >= 0
|
|
||||||
ORDER BY local_hour DESC, sent_at_ms DESC LIMIT 1
|
ORDER BY local_hour DESC, sent_at_ms DESC LIMIT 1
|
||||||
""",
|
""",
|
||||||
(facts.group_id, facts.day, 0, NIGHT_OWL_HOUR),
|
(facts.group_id, facts.day, 0, NIGHT_OWL_HOUR),
|
||||||
|
|||||||
@ -174,17 +174,12 @@ def render_me(
|
|||||||
|
|
||||||
|
|
||||||
def favourite_hour(events: EventStore, group_id: str, uuid: str) -> int | None:
|
def favourite_hour(events: EventStore, group_id: str, uuid: str) -> int | None:
|
||||||
"""The hour somebody writes most in, or None when nothing is known.
|
"""The hour somebody writes most in, or None if they never have."""
|
||||||
|
|
||||||
Skips rows whose hour is UNKNOWN_HOUR. Those are backfilled from a counter
|
|
||||||
that had no timestamps, and counting them told every member of the group
|
|
||||||
that they write most at noon.
|
|
||||||
"""
|
|
||||||
row = events.connection.execute(
|
row = events.connection.execute(
|
||||||
"""
|
"""
|
||||||
SELECT local_hour, COUNT(*) AS messages
|
SELECT local_hour, COUNT(*) AS messages
|
||||||
FROM message_events
|
FROM message_events
|
||||||
WHERE group_id = ? AND uuid = ? AND local_hour >= 0
|
WHERE group_id = ? AND uuid = ?
|
||||||
GROUP BY local_hour
|
GROUP BY local_hour
|
||||||
ORDER BY messages DESC, local_hour ASC
|
ORDER BY messages DESC, local_hour ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|||||||
@ -28,7 +28,7 @@ PATCHES_PER_MINOR: Final = 8
|
|||||||
|
|
||||||
# Which release this build is. Bump by one per release; everything else,
|
# Which release this build is. Bump by one per release; everything else,
|
||||||
# including the version string in pyproject.toml, follows from it.
|
# including the version string in pyproject.toml, follows from it.
|
||||||
RELEASE_ORDINAL: Final = 11
|
RELEASE_ORDINAL: Final = 10
|
||||||
|
|
||||||
_POPES_FILE: Final = Path(__file__).with_name("popes.json")
|
_POPES_FILE: Final = Path(__file__).with_name("popes.json")
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from __future__ import annotations
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from signal_bot.stats.backfill import (
|
from signal_bot.stats.backfill import (
|
||||||
UNKNOWN_HOUR,
|
BACKFILL_HOUR,
|
||||||
backfilled_day,
|
backfilled_day,
|
||||||
has_legacy_counter,
|
has_legacy_counter,
|
||||||
seed_from_counter,
|
seed_from_counter,
|
||||||
@ -94,12 +94,7 @@ def test_seeded_people_are_known_to_the_roster(store: Store) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_seeded_events_carry_no_invented_detail(store: Store) -> None:
|
def test_seeded_events_carry_no_invented_detail(store: Store) -> None:
|
||||||
"""No hours, no lengths, no media -- the counter knew none of them.
|
"""No hours, no lengths, no media -- the counter knew none of them."""
|
||||||
|
|
||||||
The hour is -1 rather than any real hour. It was noon once, and
|
|
||||||
favourite_hour then told all seven people they wrote most at midday: 319
|
|
||||||
synthetic noons outweighed every genuine evening.
|
|
||||||
"""
|
|
||||||
give_legacy_counter(store, [(GROUP, "u1", "Mithra", 2)])
|
give_legacy_counter(store, [(GROUP, "u1", "Mithra", 2)])
|
||||||
seed_from_counter(store, DAY)
|
seed_from_counter(store, DAY)
|
||||||
rows = store.events.connection.execute(
|
rows = store.events.connection.execute(
|
||||||
@ -107,7 +102,7 @@ def test_seeded_events_carry_no_invented_detail(store: Store) -> None:
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
assert len(rows) == 2
|
assert len(rows) == 2
|
||||||
for row in rows:
|
for row in rows:
|
||||||
assert row["local_hour"] == UNKNOWN_HOUR
|
assert row["local_hour"] == BACKFILL_HOUR
|
||||||
assert (row["char_len"], row["media_count"], row["is_command"]) == (0, 0, 0)
|
assert (row["char_len"], row["media_count"], row["is_command"]) == (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,10 +12,9 @@ from signal_bot.animals import load_aliases
|
|||||||
from signal_bot.folding import fold
|
from signal_bot.folding import fold
|
||||||
from signal_bot.registry import CommandRegistry
|
from signal_bot.registry import CommandRegistry
|
||||||
from signal_bot.stats import periods
|
from signal_bot.stats import periods
|
||||||
from signal_bot.stats.backfill import BACKFILL_KEY, seed_from_counter
|
from signal_bot.stats.backfill import BACKFILL_KEY
|
||||||
from signal_bot.stats.commands import HANDLERS, register_stats_commands
|
from signal_bot.stats.commands import HANDLERS, register_stats_commands
|
||||||
from tests.stats_seed import GROUP, IGA, KUHY, MITHRA, Shape, wrote
|
from tests.stats_seed import GROUP, IGA, KUHY, MITHRA, Shape, wrote
|
||||||
from tests.test_stats_backfill import LEGACY as LEGACY_COUNTER
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from signal_bot.store import Store
|
from signal_bot.store import Store
|
||||||
@ -45,17 +44,6 @@ class FakeContext:
|
|||||||
self.replies.append(text)
|
self.replies.append(text)
|
||||||
|
|
||||||
|
|
||||||
def seed_from_counter_rows(store: Store, uuid: str, name: str, count: int) -> None:
|
|
||||||
"""Seed a pre-0.1.0 counter and carry it over, as the migration did."""
|
|
||||||
store.events.connection.executescript(LEGACY_COUNTER)
|
|
||||||
store.events.connection.execute(
|
|
||||||
"INSERT INTO message_counts (group_id, uuid, display_name, count) VALUES (?, ?, ?, ?)",
|
|
||||||
(GROUP, uuid, name, count),
|
|
||||||
)
|
|
||||||
store.events.connection.commit()
|
|
||||||
seed_from_counter(store, "2026-08-01")
|
|
||||||
|
|
||||||
|
|
||||||
async def run(store: Store, name: str, uuid: str = KUHY[0]) -> str:
|
async def run(store: Store, name: str, uuid: str = KUHY[0]) -> str:
|
||||||
"""Run one command and return what it said."""
|
"""Run one command and return what it said."""
|
||||||
ctx = FakeContext(store=store, message=Sender(source_uuid=uuid))
|
ctx = FakeContext(store=store, message=Sender(source_uuid=uuid))
|
||||||
@ -184,31 +172,6 @@ async def test_records_skips_somebody_with_no_days_left_after_exclusions(
|
|||||||
assert "Iga" not in rendered
|
assert "Iga" not in rendered
|
||||||
|
|
||||||
|
|
||||||
async def test_the_backfilled_day_cannot_invent_a_favourite_hour(
|
|
||||||
store: Store,
|
|
||||||
) -> None:
|
|
||||||
"""The 0.1.1 bug: everybody's favourite hour came out as 12:00.
|
|
||||||
|
|
||||||
The backfilled counter had no hours, and the placeholder was noon -- so
|
|
||||||
for every person the 319 seeded rows outvoted every real evening, and
|
|
||||||
!ja told each of them the same thing.
|
|
||||||
"""
|
|
||||||
seed_from_counter_rows(store, KUHY[0], KUHY[1], 300)
|
|
||||||
wrote(store, "2026-08-15", KUHY, 3, Shape(hour=21))
|
|
||||||
answer = await run(store, "stats_me")
|
|
||||||
assert "między 21:00 a 22:00" in answer
|
|
||||||
assert "12:00" not in answer
|
|
||||||
|
|
||||||
|
|
||||||
async def test_somebody_with_only_backfilled_messages_has_no_hour(
|
|
||||||
store: Store,
|
|
||||||
) -> None:
|
|
||||||
"""Nothing is known about when they wrote, so the line is omitted."""
|
|
||||||
seed_from_counter_rows(store, KUHY[0], KUHY[1], 5)
|
|
||||||
answer = await run(store, "stats_me")
|
|
||||||
assert "Najczęściej piszesz" not in answer
|
|
||||||
|
|
||||||
|
|
||||||
async def test_weekdays_marks_today(store: Store) -> None:
|
async def test_weekdays_marks_today(store: Store) -> None:
|
||||||
wrote(store, TODAY, MITHRA, 5)
|
wrote(store, TODAY, MITHRA, 5)
|
||||||
assert "← dziś" in await run(store, "stats_weekdays")
|
assert "← dziś" in await run(store, "stats_weekdays")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user