mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-10 20:17:02 +01:00
Per-person photo commands, where the mechanism is public and the album is not. Nothing identifying is in this repository: who the people are, what fires their photos and which file shows whom all live in one directory outside it, and the tests, the docs and the offline e2e run use three invented people instead. Several names in one message intersect -- "!alfa beta" is a photo with both -- and where an entry offers a choice the bot picks among the readings that actually have a photo, so a question the album could answer is not refused. A combination nobody photographed gets one line rather than silence, which from the group's side is indistinguishable from a broken bot. Scoping is enforced in the dispatcher, not in the handler: a command the group is not allowed resolves to nothing, so it is not answered, not counted as a command, and never named in a log line outside its own groups. A handler that quietly returned would leak all three. Commands are named by pseudonym (pack:p1), so the journal and command_uses say somebody asked for a photo and nothing about whose. Video works: the attachment goes out as data:video/mp4;filename=...;base64, which is the container's own spelling, read off its /swagger/doc.json. Told it is a photo, Signal renders a clip as an unplayable file. tool/tagger.py serves one page on loopback to fill the album in -- names are typed into the page, never as arguments, and it prints how many photos each command would have when it stops, because a command with zero is dead on arrival. Also renames the real people who were still sitting in the stats test fixtures. They remain in the history; the point is that nothing new is added to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017w1HZ3cZ7neL3rFdQ6VMBA
138 lines
5.2 KiB
Python
138 lines
5.2 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""All-time records, and the silences between them."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from signal_bot.stats.queries_period import every_day
|
|
from signal_bot.stats.records import (
|
|
busiest_day,
|
|
days_silent_before,
|
|
longest_silence,
|
|
most_media_day,
|
|
personal_best,
|
|
previous_best,
|
|
quietest_day,
|
|
)
|
|
from tests.stats_seed import ALA, BASIA, GROUP, KUHY, Shape, wrote
|
|
|
|
if TYPE_CHECKING:
|
|
from signal_bot.store import Store
|
|
|
|
|
|
def history(store: Store) -> None:
|
|
"""Four days, a two-day gap, ties, and somebody who stops writing."""
|
|
wrote(store, "2026-09-01", ALA, 10, Shape(media=3))
|
|
wrote(store, "2026-09-01", KUHY, 5)
|
|
wrote(store, "2026-09-02", ALA, 4)
|
|
wrote(store, "2026-09-02", KUHY, 4)
|
|
wrote(store, "2026-09-03", BASIA, 2)
|
|
# 09-04 and 09-05 silent.
|
|
wrote(store, "2026-09-06", KUHY, 9, Shape(media=1))
|
|
|
|
|
|
def test_no_history_yields_no_records(store: Store) -> None:
|
|
"""Day one of this release: everything empty, nothing crashing."""
|
|
days = every_day(store.events, GROUP)
|
|
assert busiest_day(days) is None
|
|
assert quietest_day(days) is None
|
|
assert longest_silence(days, "2026-09-06") is None
|
|
assert most_media_day(store.events, GROUP) is None
|
|
assert personal_best(store.events, GROUP, "u-kuhy") is None
|
|
|
|
|
|
def test_busiest_and_quietest(store: Store) -> None:
|
|
history(store)
|
|
days = every_day(store.events, GROUP)
|
|
assert busiest_day(days).day == "2026-09-01"
|
|
assert busiest_day(days).value == 15
|
|
assert quietest_day(days).day == "2026-09-03"
|
|
assert quietest_day(days).value == 2
|
|
|
|
|
|
def test_the_quietest_day_is_one_somebody_spoke_on(store: Store) -> None:
|
|
"""A silent day is a silence, not a quiet day, and is measured separately."""
|
|
history(store)
|
|
days = every_day(store.events, GROUP)
|
|
assert quietest_day(days).value > 0
|
|
assert "2026-09-04" not in days
|
|
|
|
|
|
def test_a_tie_on_the_busiest_day_goes_to_the_earlier(store: Store) -> None:
|
|
wrote(store, "2026-09-02", KUHY, 7)
|
|
wrote(store, "2026-09-01", ALA, 7)
|
|
assert busiest_day(every_day(store.events, GROUP)).day == "2026-09-01"
|
|
|
|
|
|
def test_personal_best_and_what_it_beat(store: Store) -> None:
|
|
history(store)
|
|
best = personal_best(store.events, GROUP, "u-kuhy")
|
|
assert (best.day, best.value) == ("2026-09-06", 9)
|
|
previous = previous_best(store.events, GROUP, "u-kuhy", "2026-09-06")
|
|
assert (previous.day, previous.value) == ("2026-09-01", 5)
|
|
|
|
|
|
def test_a_first_ever_day_has_nothing_to_beat(store: Store) -> None:
|
|
"""The "poprzedni rekord" clause has to be omitted, not printed as 0."""
|
|
wrote(store, "2026-09-01", BASIA, 3)
|
|
assert previous_best(store.events, GROUP, "u-basia", "2026-09-01") is None
|
|
|
|
|
|
def test_most_media_day(store: Store) -> None:
|
|
history(store)
|
|
record = most_media_day(store.events, GROUP)
|
|
assert (record.day, record.value) == ("2026-09-01", 3)
|
|
|
|
|
|
def test_a_history_with_no_media_has_no_media_record(store: Store) -> None:
|
|
wrote(store, "2026-09-01", KUHY, 4)
|
|
assert most_media_day(store.events, GROUP) is None
|
|
|
|
|
|
def test_longest_silence(store: Store) -> None:
|
|
history(store)
|
|
gap = longest_silence(every_day(store.events, GROUP), "2026-09-06")
|
|
assert (gap.start, gap.end, gap.days) == ("2026-09-04", "2026-09-05", 2)
|
|
|
|
|
|
def test_a_silence_running_to_today_counts(store: Store) -> None:
|
|
"""The gap the group is currently in is the one worth mentioning."""
|
|
wrote(store, "2026-09-01", KUHY, 1)
|
|
gap = longest_silence(every_day(store.events, GROUP), "2026-09-05")
|
|
assert (gap.start, gap.end, gap.days) == ("2026-09-02", "2026-09-05", 4)
|
|
|
|
|
|
def test_an_unbroken_history_has_no_silence(store: Store) -> None:
|
|
wrote(store, "2026-09-01", KUHY, 1)
|
|
wrote(store, "2026-09-02", KUHY, 1)
|
|
assert longest_silence(every_day(store.events, GROUP), "2026-09-02") is None
|
|
|
|
|
|
def test_the_gap_excludes_both_the_last_word_and_the_return(store: Store) -> None:
|
|
"""What makes "odezwał się po 3 dniach" true instead of off by one."""
|
|
history(store)
|
|
days = every_day(store.events, GROUP)
|
|
ala = {d: n for d, n in days.items() if d in {"2026-09-01", "2026-09-02"}}
|
|
# Recorded days are 09-01, 09-02, 09-03 and 09-06. Ala last wrote on
|
|
# the 2nd, so only the 3rd sits between that and a return on the 6th.
|
|
assert days_silent_before(days, ala, "2026-09-06") == 1
|
|
assert days_silent_before(days, {"2026-09-06": 9}, "2026-09-06") == 0
|
|
|
|
|
|
def test_somebody_who_never_wrote_is_silent_for_every_day_before_now(store: Store) -> None:
|
|
history(store)
|
|
days = every_day(store.events, GROUP)
|
|
assert days_silent_before(days, {}, "2026-09-06") == len(days) - 1
|
|
assert days_silent_before({}, {}, "2026-09-06") == 0
|
|
|
|
|
|
def test_the_backfilled_day_is_kept_out_of_records(store: Store) -> None:
|
|
"""A 22-hour window filed as a day must not become somebody's best."""
|
|
wrote(store, "2026-08-30", ALA, 98)
|
|
wrote(store, "2026-09-01", ALA, 10)
|
|
assert personal_best(store.events, GROUP, "u-ala").value == 98
|
|
excluded = personal_best(store.events, GROUP, "u-ala", exclude="2026-08-30")
|
|
assert (excluded.day, excluded.value) == ("2026-09-01", 10)
|
|
assert "2026-08-30" not in every_day(store.events, GROUP, exclude="2026-08-30")
|