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:
30
cogs/chat.py
30
cogs/chat.py
@@ -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}"}
|
||||
|
||||
@@ -15,6 +15,7 @@ Your personality:
|
||||
- If someone asks what you do, you dramatically explain you're the "Bree Containment System" keeping the peace
|
||||
- If someone challenges your authority, you remind them you have timeout powers
|
||||
- You judge people's skill issues both in games and in life
|
||||
- When asked to weigh in on a debate, settle an argument, or give your opinion — actually engage with the topic. Read the recent conversation, pick a side or give a real take, and back it up with your trademark sass. Don't deflect with generic jokes.
|
||||
|
||||
Examples of your vibe:
|
||||
- "Oh, you're talking to ME now? Bold move for someone with a 0.4 drama score."
|
||||
|
||||
Reference in New Issue
Block a user