From da9e387b105b0d8252750e38b4235513b38ff8f8 Mon Sep 17 00:00:00 2001 From: Zylan Date: Thu, 24 Apr 2025 17:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=87=8D=E7=BD=AE=E8=AE=B0?= =?UTF-8?q?=E5=BF=86=E5=91=BD=E4=BB=A4=E5=8F=8A=E7=9B=B8=E5=85=B3=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E6=9B=B4=E6=96=B0=20README?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E4=BB=A5=E5=8F=8D=E6=98=A0=E8=AF=A5?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=EF=BC=8C=E6=8F=90=E5=8D=87=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E6=80=A7=E5=92=8C=E5=8F=AF=E8=AF=BB=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 1 - commands/handlers.py | 66 ++------------------------------------------ commands/registry.py | 12 +------- 3 files changed, 3 insertions(+), 76 deletions(-) diff --git a/README.MD b/README.MD index 43d3f6d..dff78c8 100644 --- a/README.MD +++ b/README.MD @@ -180,7 +180,6 @@ python main.py ##### 基础系统命令 - `info`、`帮助`、`指令` - 显示机器人的帮助信息 - `骂一下 @用户名` - 让机器人骂指定用户(仅群聊) -- `reset`、`重置` - 重置机器人缓存的上下文历史 ##### Perplexity AI 命令 - `ask 问题内容` - 使用 Perplexity AI 进行深度查询(需@机器人) diff --git a/commands/handlers.py b/commands/handlers.py index 4124973..68eb423 100644 --- a/commands/handlers.py +++ b/commands/handlers.py @@ -3,12 +3,8 @@ import random from typing import Optional, Match, Dict, Any import json # 确保已导入json from datetime import datetime # 确保已导入datetime -import os # 导入os模块用于文件路径操作 -from function.func_duel import DuelRankSystem - -# 导入AI模型 -from ai_providers.ai_deepseek import DeepSeek -from ai_providers.ai_chatgpt import ChatGPT +# import os # 导入os模块用于文件路径操作 +# from function.func_duel import DuelRankSystem # 前向引用避免循环导入 from typing import TYPE_CHECKING @@ -46,7 +42,6 @@ def handle_help(ctx: 'MessageContext', match: Optional[Match]) -> bool: "【群聊工具】", "- summary/总结", "- clearmessages/清除历史", - "- reset/重置", "" ] help_text = "\n".join(help_text) @@ -92,63 +87,6 @@ def handle_check_equipment(ctx: 'MessageContext', match: Optional[Match]) -> boo ctx.send_text("⚠️ 查看装备失败") return False -def handle_reset_memory(ctx: 'MessageContext', match: Optional[Match]) -> bool: - """ - 处理 "重置记忆" 命令 - - 匹配: reset/重置/重置记忆 - """ - chat_id = ctx.get_receiver() - chat_model = ctx.chat # 使用上下文中的chat模型 - - if not chat_model: - ctx.send_text("⚠️ 未配置AI模型,无需重置") - return True - - try: - # 检查并调用不同AI模型的清除记忆方法 - if hasattr(chat_model, 'conversation_list') and chat_id in getattr(chat_model, 'conversation_list', {}): - # 判断是哪种类型的模型并执行相应的重置操作 - model_name = chat_model.__class__.__name__ - - if isinstance(chat_model, DeepSeek): - # DeepSeek模型 - del chat_model.conversation_list[chat_id] - if ctx.logger: ctx.logger.info(f"已重置DeepSeek对话记忆: {chat_id}") - result = "✅ 已重置DeepSeek对话记忆,开始新的对话" - - elif isinstance(chat_model, ChatGPT): - # ChatGPT模型 - # 保留系统提示,删除其他历史 - if len(chat_model.conversation_list[chat_id]) > 0: - system_msgs = [msg for msg in chat_model.conversation_list[chat_id] if msg["role"] == "system"] - chat_model.conversation_list[chat_id] = system_msgs - if ctx.logger: ctx.logger.info(f"已重置ChatGPT对话记忆(保留系统提示): {chat_id}") - result = "✅ 已重置ChatGPT对话记忆,保留系统提示,开始新的对话" - else: - result = f"⚠️ {model_name} 对话记忆已为空,无需重置" - - else: - # 通用处理方式:直接删除对话记录 - del chat_model.conversation_list[chat_id] - if ctx.logger: ctx.logger.info(f"已通过通用方式重置{model_name}对话记忆: {chat_id}") - result = f"✅ 已重置{model_name}对话记忆,开始新的对话" - else: - # 对于没有找到会话记录的情况 - model_name = chat_model.__class__.__name__ if chat_model else "未知模型" - if ctx.logger: ctx.logger.info(f"未找到{model_name}对话记忆: {chat_id}") - result = f"⚠️ 未找到与{model_name}的对话记忆,无需重置" - - # 发送结果消息 - ctx.send_text(result) - - return True - - except Exception as e: - if ctx.logger: ctx.logger.error(f"重置对话记忆失败: {e}") - ctx.send_text(f"❌ 重置对话记忆失败: {e}") - return False - def handle_summary(ctx: 'MessageContext', match: Optional[Match]) -> bool: """ 处理 "消息总结" 命令 diff --git a/commands/registry.py b/commands/registry.py index d022e2a..5034c70 100644 --- a/commands/registry.py +++ b/commands/registry.py @@ -25,16 +25,6 @@ COMMANDS = [ description="显示机器人的帮助信息" ), - Command( - name="reset_memory", - pattern=re.compile(r"^(reset|重置)$", re.IGNORECASE), - scope="both", # 群聊和私聊都支持 - need_at=True, # 需要@机器人 - priority=20, # 优先级较高 - handler=handle_reset_memory, - description="重置机器人缓存里的上下文历史" - ), - # ======== Perplexity AI 命令 ======== Command( name="perplexity_ask", @@ -102,7 +92,7 @@ COMMANDS = [ # ======== 新闻和实用工具 ======== Command( name="weather_forecast", - pattern=re.compile(r"^(?:天气预报|预报)\s+(.+)$"), # 匹配 天气预报/预报 城市名 + pattern=re.compile(r"^(?:天气预报|天气)\s+(.+)$"), # 匹配 天气预报/预报 城市名 scope="both", # 群聊和私聊都支持 need_at=True, # 需要@机器人 priority=38, # 优先级比天气高一点