feat: give bot full conversation context on @mentions for real engagement

When @mentioned, fetch recent messages from ALL users in the channel
(up to 15 messages) instead of only the mentioner's messages. This lets
the bot understand debates and discussions it's asked to weigh in on.

Also update the personality prompt to engage with topics substantively
when asked for opinions, rather than deflecting with generic jokes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 14:14:46 -05:00
parent 3d252ee729
commit 0449c8c30d
2 changed files with 24 additions and 7 deletions

View File

@@ -319,18 +319,34 @@ class ChatCog(commands.Cog):
if scan_summary:
extra_context += f"[You just scanned recent chat. Results: {scan_summary}]\n"
recent_user_msgs = []
# When @mentioned, fetch recent channel conversation (all users)
# so the bot has full context of what's being discussed.
# For proactive/reply-to-bot, just fetch the mentioner's messages.
recent_msgs = []
fetch_all_users = self.bot.user in message.mentions
try:
async for msg in message.channel.history(limit=50, before=message):
if msg.author.id == message.author.id and msg.content and msg.content.strip():
recent_user_msgs.append(msg.content[:200])
if len(recent_user_msgs) >= 10:
if not msg.content or not msg.content.strip():
continue
if msg.author.bot:
# Include bot's own replies for conversational continuity
if msg.author.id == self.bot.user.id:
recent_msgs.append((msg.author.display_name, msg.content[:200]))
if len(recent_msgs) >= 15:
break
continue
if fetch_all_users or msg.author.id == message.author.id:
recent_msgs.append((msg.author.display_name, msg.content[:200]))
if len(recent_msgs) >= 15:
break
except discord.HTTPException:
pass
if recent_user_msgs:
recent_lines = "\n".join(f"- {m}" for m in reversed(recent_user_msgs))
extra_context += f"[{message.author.display_name}'s recent messages:\n{recent_lines}]\n"
if recent_msgs:
recent_lines = "\n".join(
f"- {name}: {text}" for name, text in reversed(recent_msgs)
)
label = "Recent conversation" if fetch_all_users else f"{message.author.display_name}'s recent messages"
extra_context += f"[{label}:\n{recent_lines}]\n"
self._chat_history[ch_id].append(
{"role": "user", "content": f"{score_context}\n{extra_context}{reply_context}{message.author.display_name}: {content}"}