fix: Enhance emoji and sticker data validation in get_ai_response function

This commit is contained in:
Slipstream 2025-05-28 15:24:54 -06:00
parent a0caf07e76
commit 282a80f79b
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -1494,7 +1494,7 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
# Check if it's a known custom emoji
emoji_data = await cog.emoji_manager.get_emoji(full_item_name_with_colons)
if emoji_data:
if isinstance(emoji_data, dict): # Check if emoji_data is a dictionary
emoji_id = emoji_data.get("id")
is_animated = emoji_data.get("animated", False)
if emoji_id:
@ -1502,11 +1502,13 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
modified_content = modified_content.replace(full_item_name_with_colons, discord_emoji_syntax)
print(f"Replaced custom emoji '{full_item_name_with_colons}' with Discord syntax: {discord_emoji_syntax}")
else:
print(f"Found custom emoji '{full_item_name_with_colons}' but no ID stored.")
print(f"Found custom emoji '{full_item_name_with_colons}' (dict) but no ID stored.")
elif emoji_data is not None: # Log if it's not a dict but also not None
print(f"Warning: emoji_data for '{full_item_name_with_colons}' is not a dict: {type(emoji_data)}")
# Check if it's a known custom sticker
sticker_data = await cog.emoji_manager.get_sticker(full_item_name_with_colons)
if sticker_data:
if isinstance(sticker_data, dict): # Check if sticker_data is a dictionary
sticker_id = sticker_data.get("id")
if sticker_id:
# Remove the sticker text from the content
@ -1514,7 +1516,9 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
sticker_ids_to_send.append(sticker_id)
print(f"Found custom sticker '{full_item_name_with_colons}', removed from content, added ID '{sticker_id}' to send list.")
else:
print(f"Found custom sticker '{full_item_name_with_colons}' but no ID stored.")
print(f"Found custom sticker '{full_item_name_with_colons}' (dict) but no ID stored.")
elif sticker_data is not None: # Log if it's not a dict but also not None
print(f"Warning: sticker_data for '{full_item_name_with_colons}' is not a dict: {type(sticker_data)}")
# Clean up any double spaces or leading/trailing whitespace after replacements
modified_content = re.sub(r'\s+', ' ', modified_content).strip()