fix: separate context from new messages so prior-cycle chat doesn't inflate scores
The conversation analysis was re-scoring old messages alongside new ones, causing users to get penalized repeatedly for already-scored messages. A "--- NEW MESSAGES ---" separator now marks which messages are new, and the prompt instructs the LLM to score only those. Also fixes bot-mention detection to require an explicit @mention in message text rather than treating reply-pings as scans (so toxic replies to bot warnings aren't silently skipped). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -87,19 +87,18 @@ class SentimentCog(commands.Cog):
|
||||
if self.bot.drama_tracker.is_immune(message.author.id):
|
||||
return
|
||||
|
||||
# Messages directed at the bot (mentions, replies) shouldn't be scored
|
||||
# for toxicity — but @mentions can trigger a scan of recent chat
|
||||
directed_at_bot = self.bot.user in message.mentions
|
||||
if not directed_at_bot and message.reference and message.reference.message_id:
|
||||
ref = message.reference.cached_message
|
||||
if ref and ref.author.id == self.bot.user.id:
|
||||
directed_at_bot = True
|
||||
if directed_at_bot:
|
||||
# @mention (not just reply-to-bot) triggers a mention scan
|
||||
if self.bot.user in message.mentions:
|
||||
mention_config = config.get("mention_scan", {})
|
||||
if mention_config.get("enabled", True):
|
||||
await self._maybe_start_mention_scan(message, mention_config)
|
||||
# Explicit @mention of the bot triggers a mention scan instead of scoring.
|
||||
# Reply-pings (Discord auto-adds replied-to user to mentions) should NOT
|
||||
# trigger scans — and reply-to-bot messages should still be scored normally
|
||||
# so toxic replies to bot warnings aren't silently skipped.
|
||||
bot_mentioned_in_text = (
|
||||
f"<@{self.bot.user.id}>" in (message.content or "")
|
||||
or f"<@!{self.bot.user.id}>" in (message.content or "")
|
||||
)
|
||||
if bot_mentioned_in_text:
|
||||
mention_config = config.get("mention_scan", {})
|
||||
if mention_config.get("enabled", True):
|
||||
await self._maybe_start_mention_scan(message, mention_config)
|
||||
return
|
||||
|
||||
# Skip if empty
|
||||
@@ -166,6 +165,7 @@ class SentimentCog(commands.Cog):
|
||||
history_messages.reverse() # chronological order
|
||||
|
||||
# Combine: history (context) + buffered (new messages to analyze)
|
||||
new_message_start = len(history_messages)
|
||||
all_messages = history_messages + messages
|
||||
|
||||
# Build msg_id_to_author lookup for reply resolution
|
||||
@@ -215,6 +215,7 @@ class SentimentCog(commands.Cog):
|
||||
conversation,
|
||||
channel_context=channel_context,
|
||||
user_notes_map=user_notes_map,
|
||||
new_message_start=new_message_start,
|
||||
)
|
||||
|
||||
if result is None:
|
||||
@@ -233,6 +234,7 @@ class SentimentCog(commands.Cog):
|
||||
conversation,
|
||||
channel_context=channel_context,
|
||||
user_notes_map=user_notes_map,
|
||||
new_message_start=new_message_start,
|
||||
)
|
||||
if heavy_result is not None:
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user