Add user notes and recent message history to chat context

When the bot replies (proactive or mentioned), it now fetches the
user's drama tracker notes and their last ~10 messages in the channel.
Gives the LLM real context for personalized replies instead of
generic roasts on bare pings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-23 13:44:04 -05:00
parent 3261cdd21c
commit 66031cd9f9

View File

@@ -163,8 +163,27 @@ class ChatCog(commands.Cog):
context_parts.append(f"{user_data.offense_count} offense(s)")
score_context = f"[Server context: {message.author.display_name}{', '.join(context_parts)}]"
# Gather user notes and recent messages for richer context
extra_context = ""
user_notes = self.bot.drama_tracker.get_user_notes(message.author.id)
if user_notes:
extra_context += f"[Notes about {message.author.display_name}: {user_notes}]\n"
recent_user_msgs = []
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:
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"
self._chat_history[ch_id].append(
{"role": "user", "content": f"{score_context}\n{reply_context}{message.author.display_name}: {content}"}
{"role": "user", "content": f"{score_context}\n{extra_context}{reply_context}{message.author.display_name}: {content}"}
)
active_prompt = self._get_active_prompt()
@@ -183,6 +202,8 @@ class ChatCog(commands.Cog):
response = re.sub(r"\[Server context:[^\]]*\]\n?", "", response)
response = re.sub(r"\[Replying to bot's message:[^\]]*\]\n?", "", response)
response = re.sub(r"\[\w[\w ]* said:[^\]]*\]\n?", "", response)
response = re.sub(r"\[Notes about [^\]]*\]\n?", "", response)
response = re.sub(r"\[[^\]]*'s recent messages:[\s\S]*?\]\n?", "", response)
# Catch reformatted metadata (LLM drops prefix but keeps content)
response = re.sub(r"\[[^\]]*#[a-z-]+[^\]]*(?:drama score|offense)[^\]]*\]\n?", "", response, flags=re.IGNORECASE)
response = response.strip()