# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """Which messages count toward the daily tally, and which chats we listen to.""" from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: from signal_bot.config import Config from signal_bot.models import IncomingMessage def is_watched_group(message: IncomingMessage, config: Config) -> bool: """True only for messages from the one group the bot is scoped to. A linked Signal device receives every direct conversation and every group on the account. This predicate is the entire boundary between "a bot in one group" and "a bot reading all of your chats", so it is deliberately written as an explicit group-id equality rather than a falsy check: a direct message has no group id at all and must never reach a handler. """ if message.group_id is None: return False return message.group_id == config.group_id def should_count(message: IncomingMessage) -> bool: """True when a message should add to its sender's tally. Reactions and stickers are not messages for tally purposes, and a frame with no text body carries nothing to count. """ if message.is_reaction or message.has_sticker: return False return bool(message.text) def format_tally(rows: list[tuple[str, int]]) -> str: """Render the daily report, or a placeholder when nobody spoke.""" if not rows: return "Brak wiadomosci dzisiaj." width = max(len(name) for name, _ in rows) lines = [f"{name.ljust(width)} {count}" for name, count in rows] return "\n".join(lines)