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:
+10
-3
@@ -28,6 +28,13 @@ class ReactionCog(commands.Cog):
|
|||||||
if not message.content or not message.content.strip():
|
if not message.content or not message.content.strip():
|
||||||
return
|
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
|
# RNG gate
|
||||||
chance = cfg.get("chance", 0.15)
|
chance = cfg.get("chance", 0.15)
|
||||||
if random.random() > chance:
|
if random.random() > chance:
|
||||||
@@ -41,9 +48,9 @@ class ReactionCog(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Fire and forget so we don't block anything
|
# 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:
|
try:
|
||||||
emoji = await self.bot.llm.pick_reaction(
|
emoji = await self.bot.llm.pick_reaction(
|
||||||
message.content, message.channel.name,
|
message.content, message.channel.name,
|
||||||
@@ -52,7 +59,7 @@ class ReactionCog(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await message.add_reaction(emoji)
|
await message.add_reaction(emoji)
|
||||||
self._last_reaction[ch_id] = now
|
self._last_reaction[ch_id] = time.monotonic()
|
||||||
logger.info(
|
logger.info(
|
||||||
"Reacted %s to %s in #%s: %s",
|
"Reacted %s to %s in #%s: %s",
|
||||||
emoji, message.author.display_name,
|
emoji, message.author.display_name,
|
||||||
|
|||||||
@@ -166,3 +166,4 @@ reactions:
|
|||||||
enabled: true
|
enabled: true
|
||||||
chance: 0.15 # Probability of evaluating a message for reaction
|
chance: 0.15 # Probability of evaluating a message for reaction
|
||||||
cooldown_seconds: 45 # Per-channel cooldown between reactions
|
cooldown_seconds: 45 # Per-channel cooldown between reactions
|
||||||
|
excluded_channels: [] # Channel names or IDs to skip reactions in
|
||||||
|
|||||||
+1
-1
@@ -782,7 +782,7 @@ class LLMClient:
|
|||||||
model=self.model,
|
model=self.model,
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "system", "content": prompt},
|
{"role": "system", "content": prompt},
|
||||||
{"role": "user", "content": f"[#{channel_name}] {message_text}"},
|
{"role": "user", "content": f"[#{channel_name}] {message_text[:500]}"},
|
||||||
],
|
],
|
||||||
**temp_kwargs,
|
**temp_kwargs,
|
||||||
max_completion_tokens=16,
|
max_completion_tokens=16,
|
||||||
|
|||||||
Reference in New Issue
Block a user