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 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 11:28:20 -05:00
parent a8e8b63f5e
commit 97e5738a2f
3 changed files with 12 additions and 4 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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,