Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,7 @@ def load_data_from_webdav():
|
|
131 |
if response.status_code == 200:
|
132 |
data = json.loads(response.text)
|
133 |
|
134 |
-
chatHistories = data
|
135 |
GROUP_SETTINGS = {int(k): v for k, v in data.get('GROUP_SETTINGS', {}).items()}
|
136 |
USER_SETTINGS = {int(k): v for k, v in data.get('USER_SETTINGS', {}).items()}
|
137 |
USER_LAST_ACTIVE = {int(k): datetime.fromisoformat(v) for k, v in data.get('USER_LAST_ACTIVE', {}).items()}
|
@@ -402,7 +402,7 @@ async def processAiMessage(chatId, userMessage, fromUserId, message_id, fromUser
|
|
402 |
return
|
403 |
|
404 |
history = chatHistories.get(chatId, [])
|
405 |
-
|
406 |
if isGroupChat:
|
407 |
# 从群组设置获取温度和提示词
|
408 |
userTemp = GROUP_SETTINGS.get(chatId, {}).get('temperature', DEFAULT_TEMP)
|
@@ -411,7 +411,7 @@ async def processAiMessage(chatId, userMessage, fromUserId, message_id, fromUser
|
|
411 |
# 从用户设置获取温度和提示词
|
412 |
userTemp = USER_SETTINGS.get(fromUserId, {}).get('temperature', DEFAULT_TEMP)
|
413 |
userPromptIndex = USER_SETTINGS.get(fromUserId, {}).get('prompt_index', CURRENT_PROMPT_INDEX)
|
414 |
-
|
415 |
currentPrompt = PROMPT_TEMPLATES.get(userPromptIndex, "")
|
416 |
|
417 |
user_last_active = USER_LAST_ACTIVE.get(fromUserId, None)
|
@@ -435,6 +435,11 @@ async def processAiMessage(chatId, userMessage, fromUserId, message_id, fromUser
|
|
435 |
- 群组最后活跃时间: {group_info['last_active'].strftime("%Y-%m-%d %H:%M:%S") if group_info and group_info.get('last_active') else "未知"}
|
436 |
- 群组活跃用户数: {len(group_active_users) if group_active_users else "未知"}
|
437 |
"""
|
|
|
|
|
|
|
|
|
|
|
438 |
history.append({'role': 'user', 'content': userMessage})
|
439 |
|
440 |
if len(history) > MAX_HISTORY_LENGTH:
|
@@ -602,7 +607,6 @@ async def banUser(chatId, userId):
|
|
602 |
async def unbanUser(chatId, userId):
|
603 |
if userId in BANNED_USERS:
|
604 |
del BANNED_USERS[userId]
|
605 |
-
|
606 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
607 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
608 |
|
|
|
131 |
if response.status_code == 200:
|
132 |
data = json.loads(response.text)
|
133 |
|
134 |
+
chatHistories = data.get('chatHistories', {})
|
135 |
GROUP_SETTINGS = {int(k): v for k, v in data.get('GROUP_SETTINGS', {}).items()}
|
136 |
USER_SETTINGS = {int(k): v for k, v in data.get('USER_SETTINGS', {}).items()}
|
137 |
USER_LAST_ACTIVE = {int(k): datetime.fromisoformat(v) for k, v in data.get('USER_LAST_ACTIVE', {}).items()}
|
|
|
402 |
return
|
403 |
|
404 |
history = chatHistories.get(chatId, [])
|
405 |
+
|
406 |
if isGroupChat:
|
407 |
# 从群组设置获取温度和提示词
|
408 |
userTemp = GROUP_SETTINGS.get(chatId, {}).get('temperature', DEFAULT_TEMP)
|
|
|
411 |
# 从用户设置获取温度和提示词
|
412 |
userTemp = USER_SETTINGS.get(fromUserId, {}).get('temperature', DEFAULT_TEMP)
|
413 |
userPromptIndex = USER_SETTINGS.get(fromUserId, {}).get('prompt_index', CURRENT_PROMPT_INDEX)
|
414 |
+
|
415 |
currentPrompt = PROMPT_TEMPLATES.get(userPromptIndex, "")
|
416 |
|
417 |
user_last_active = USER_LAST_ACTIVE.get(fromUserId, None)
|
|
|
435 |
- 群组最后活跃时间: {group_info['last_active'].strftime("%Y-%m-%d %H:%M:%S") if group_info and group_info.get('last_active') else "未知"}
|
436 |
- 群组活跃用户数: {len(group_active_users) if group_active_users else "未知"}
|
437 |
"""
|
438 |
+
|
439 |
+
if chatId not in chatHistories:
|
440 |
+
chatHistories[chatId] = []
|
441 |
+
history = chatHistories[chatId]
|
442 |
+
|
443 |
history.append({'role': 'user', 'content': userMessage})
|
444 |
|
445 |
if len(history) > MAX_HISTORY_LENGTH:
|
|
|
607 |
async def unbanUser(chatId, userId):
|
608 |
if userId in BANNED_USERS:
|
609 |
del BANNED_USERS[userId]
|
|
|
610 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
611 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
612 |
|