bots know who you are and where you live

This commit is contained in:
2026-05-24 14:12:11 -04:00
parent 4a6d361997
commit 879cd5cbe8
2 changed files with 210 additions and 8 deletions
+35 -2
View File
@@ -50,6 +50,38 @@ intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
def get_user_info(user: discord.User | discord.Member) -> str:
"""Format user information for inclusion in bot prompts."""
parts: list[str] = []
if user.global_name:
parts.append(f"Global Name: {user.global_name}")
nick = getattr(user, "nick", None)
if nick:
parts.append(f"Nickname: {nick}")
top_role = getattr(user, "top_role", None)
if top_role and top_role.name != "@everyone":
parts.append(f"Top Role: {top_role.name}")
activities = getattr(user, "activities", None)
if activities:
activity_names = [
getattr(a, "name", str(a))
for a in activities
if getattr(a, "name", "") != "custom_status"
]
if activity_names:
parts.append(f"Activities: {', '.join(activity_names)}")
joined_at = getattr(user, "joined_at", None)
if joined_at:
parts.append(f"Joined: {joined_at.strftime('%Y-%m-%d')}")
parts.append(f"Username: {user.name}")
parts.append(f"User ID: {user.id}")
parts.append(
f"Account Created: {user.created_at.strftime('%Y-%m-%d') if user.created_at else 'Unknown'}"
)
return "\n".join(parts)
# Initialize TTS engine
tts_engine: tts.TTSEngine | None = None
try:
@@ -441,7 +473,7 @@ async def _speak_with_bot(
return
_, system_prompt, _, _ = bot_info
system_prompt_edit = f"{system_prompt}\nKeep your responses under 2-3 sentences."
system_prompt_edit = f"{system_prompt}\nKeep your responses under 2-3 sentences.\n\nUser Information:\n{get_user_info(ctx.author)}"
# Determine language for the chosen voice
chosen_voice = voice or TTS_VOICE
@@ -497,6 +529,7 @@ async def _speak_with_bot(
guild_id=str(ctx.guild.id) if ctx.guild else None,
)
await ctx.send(f"**{bot_name}**: {bot_response}")
await ctx.send(f"Generating speech for **{bot_name}**...")
audio_buffer = engine.generate_audio(
bot_response,
@@ -834,7 +867,7 @@ async def handle_chat(
logger.info("Chat prompts: %s", prompts)
system_prompt_edit = f"{system_prompt}\nKeep your responses under 2-3 sentences."
system_prompt_edit = f"{system_prompt}\nKeep your responses under 2-3 sentences.\n\nUser Information:\n{get_user_info(ctx.author)}"
try:
bot_response = llama_wrapper.chat_completion_with_history(