from __future__ import annotations from typing import Any REACTION_VARIANTS: dict[str, list[str]] = { "like": ["\u2764\ufe0f", "\U0001f44d", "\U0001f90d", "\U0001f499", "\U0001f49c"], "ack": ["\U0001f44d", "\u2705", "\U0001f44c"], "processing": ["\u23f3", "\U0001f916", "\U0001f4ac"], "done": ["\u2705", "\U0001f44d", "\U0001f389"], "error": ["\u274c", "\u26a0\ufe0f", "\U0001f6ab"], "thinking": ["\U0001f4ad", "\U0001f9e0", "\U0001f914"], "searching": ["\U0001f50d", "\U0001f50e", "\U0001f4da"], "generating": ["\u2728", "\U0001f4dd", "\U0001f3a8"], } def get_reaction_variant(action: str, index: int = 0) -> str: variants = REACTION_VARIANTS.get(action, ["\u2764\ufe0f"]) if index < 0: return variants[0] return variants[index % len(variants)] def get_all_reaction_actions() -> list[str]: return list(REACTION_VARIANTS.keys()) def resolve_reaction_emoji(action_or_emoji: str) -> str: if action_or_emoji in REACTION_VARIANTS: return get_reaction_variant(action_or_emoji, 0) return action_or_emoji class ReactionNotificationTriggerFilter: def __init__(self, config: dict[str, Any] | None = None): cfg = config or {} react_cfg = cfg.get("reaction_notifications", {}) if isinstance(react_cfg, dict): self._mode = react_cfg.get("mode", "off") self._whitelist = react_cfg.get("whitelist", []) else: self._mode = str(react_cfg) if react_cfg else "off" self._whitelist = [] def should_notify(self, action: str, chat_id: str | None = None) -> bool: if self._mode == "off": return False if self._mode == "all": return True if self._mode == "own": return True if self._mode == "whitelist" and chat_id: return chat_id in self._whitelist return False def notify_reaction(self, action: str) -> str | None: if not self.should_notify(action): return None return get_reaction_variant(action, 0)