modified: bot.py
This commit is contained in:
14
bot.py
14
bot.py
@@ -1,4 +1,4 @@
|
||||
__version__ = "dev-0.9.3"
|
||||
__version__ = "dev-0.9.4"
|
||||
__all__ = ["Discordbot-chatai (Discord)"]
|
||||
__author__ = "SimolZimol"
|
||||
|
||||
@@ -1326,6 +1326,16 @@ async def process_ai_queue():
|
||||
|
||||
try:
|
||||
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}"})
|
||||
|
||||
messages = [
|
||||
@@ -1366,7 +1376,7 @@ async def process_ai_queue():
|
||||
user_history.append({"role": "assistant", "content": assistant_message})
|
||||
|
||||
# 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:
|
||||
logger.error(f"Processing errors: {e}")
|
||||
|
||||
Reference in New Issue
Block a user