From 97e5738a2f835067499c968476b216956933084f Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 1 Mar 2026 11:28:20 -0500 Subject: [PATCH] fix: address review feedback for ReactionCog - Use time.monotonic() at reaction time instead of stale message-receive timestamp - Add excluded_channels config and filtering - Truncate message content to 500 chars in pick_reaction Co-Authored-By: Claude Opus 4.6 --- cogs/reactions.py | 13 ++++++++++--- config.yaml | 1 + utils/llm_client.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cogs/reactions.py b/cogs/reactions.py index a984b69..dd86777 100644 --- a/cogs/reactions.py +++ b/cogs/reactions.py @@ -28,6 +28,13 @@ class ReactionCog(commands.Cog): if not message.content or not message.content.strip(): return + # Channel exclusion + excluded = cfg.get("excluded_channels", []) + if excluded: + ch_name = getattr(message.channel, "name", "") + if message.channel.id in excluded or ch_name in excluded: + return + # RNG gate chance = cfg.get("chance", 0.15) if random.random() > chance: @@ -41,9 +48,9 @@ class ReactionCog(commands.Cog): return # Fire and forget so we don't block anything - asyncio.create_task(self._try_react(message, ch_id, now)) + asyncio.create_task(self._try_react(message, ch_id)) - async def _try_react(self, message: discord.Message, ch_id: int, now: float): + async def _try_react(self, message: discord.Message, ch_id: int): try: emoji = await self.bot.llm.pick_reaction( message.content, message.channel.name, @@ -52,7 +59,7 @@ class ReactionCog(commands.Cog): return await message.add_reaction(emoji) - self._last_reaction[ch_id] = now + self._last_reaction[ch_id] = time.monotonic() logger.info( "Reacted %s to %s in #%s: %s", emoji, message.author.display_name, diff --git a/config.yaml b/config.yaml index 3283927..5af48c5 100644 --- a/config.yaml +++ b/config.yaml @@ -166,3 +166,4 @@ reactions: enabled: true chance: 0.15 # Probability of evaluating a message for reaction cooldown_seconds: 45 # Per-channel cooldown between reactions + excluded_channels: [] # Channel names or IDs to skip reactions in diff --git a/utils/llm_client.py b/utils/llm_client.py index 4d9a1a0..ac72cdc 100644 --- a/utils/llm_client.py +++ b/utils/llm_client.py @@ -782,7 +782,7 @@ class LLMClient: model=self.model, messages=[ {"role": "system", "content": prompt}, - {"role": "user", "content": f"[#{channel_name}] {message_text}"}, + {"role": "user", "content": f"[#{channel_name}] {message_text[:500]}"}, ], **temp_kwargs, max_completion_tokens=16,