modified: bot.py

This commit is contained in:
SimolZimol
2025-08-17 23:20:12 +02:00
parent 9574273d19
commit 2e35c2dc45

14
bot.py
View File

@@ -1,4 +1,4 @@
__version__ = "dev-0.9.3" __version__ = "dev-0.9.4"
__all__ = ["Discordbot-chatai (Discord)"] __all__ = ["Discordbot-chatai (Discord)"]
__author__ = "SimolZimol" __author__ = "SimolZimol"
@@ -1326,6 +1326,16 @@ async def process_ai_queue():
try: try:
user_history = user_data.get(user_history_field, []) user_history = user_data.get(user_history_field, [])
# Ensure user_history is a list, not a string
if isinstance(user_history, str):
try:
user_history = json.loads(user_history)
except (json.JSONDecodeError, ValueError):
user_history = []
elif not isinstance(user_history, list):
user_history = []
user_history.append({"role": "user", "content": f"{user_name}: {prompt}"}) user_history.append({"role": "user", "content": f"{user_name}: {prompt}"})
messages = [ messages = [
@@ -1366,7 +1376,7 @@ async def process_ai_queue():
user_history.append({"role": "assistant", "content": assistant_message}) user_history.append({"role": "assistant", "content": assistant_message})
# Update the relevant user history field # Update the relevant user history field
update_user_data(user_data["user_id"], guild_id, user_history_field, json.dumps(user_history)) update_user_data(user_data["user_id"], guild_id, user_history_field, user_history)
except Exception as e: except Exception as e:
logger.error(f"Processing errors: {e}") logger.error(f"Processing errors: {e}")