diff --git a/wechatter/app/routers/wechat.py b/wechatter/app/routers/wechat.py index 52cedaf..fe78b7e 100644 --- a/wechatter/app/routers/wechat.py +++ b/wechatter/app/routers/wechat.py @@ -10,7 +10,7 @@ from wechatter.message import MessageHandler from wechatter.message_forwarder import MessageForwarder from wechatter.models.message import Message -from wechatter.notifier import Notifier +from wechatter.sender import notify_logged_in, notify_logged_out from wechatter.sqlite.sqlite_manager import SqliteManager router = APIRouter() @@ -79,10 +79,10 @@ def handle_system_event(content: str) -> None: # 判断是否为机器人登录消息 if content_dict["event"] == "login": print("机器人登录成功") - Notifier.notify_logged_in() + notify_logged_in() elif content_dict["event"] == "logout": print("机器人已退出登录") - Notifier.notify_logged_out() + notify_logged_out() elif content_dict["event"] == "error": pass else: diff --git a/wechatter/commands/_commands/copilot_gpt4.py b/wechatter/commands/_commands/copilot_gpt4.py index 38f2273..32aefbe 100644 --- a/wechatter/commands/_commands/copilot_gpt4.py +++ b/wechatter/commands/_commands/copilot_gpt4.py @@ -1,4 +1,3 @@ -# 使用 Copilot-GPT4-Server 回复 from typing import List, Union from loguru import logger @@ -106,6 +105,7 @@ def _gptx(model: str, to: SendTo, message: str = "") -> None: chat_info = CopilotGPT4.get_chating_chat_info(wx_id, model) if message == "": # /gpt4 # 判断对话是否有效 + _send_text_msg(to, "正在创建新对话...") if chat_info is None or CopilotGPT4.is_chat_valid(chat_info): CopilotGPT4.create_chat(wx_id=wx_id, model=model) logger.info("创建新对话成功") @@ -115,6 +115,7 @@ def _gptx(model: str, to: SendTo, message: str = "") -> None: _send_text_msg(to, "对话未开始,继续上一次对话") else: # /gpt4 # 如果没有对话记录,则创建新对话 + _send_text_msg(to, f"正在调用 {model} 进行对话...") if chat_info is None: chat_info = CopilotGPT4.create_chat(wx_id=wx_id, model=model) logger.info("无历史对话记录,创建新对话成功") @@ -159,6 +160,7 @@ def _gptx_continue(model: str, to: SendTo, message: str = "") -> None: logger.info("请输入对话记录编号") _send_text_msg(to, "请输入对话记录编号") return + _send_text_msg(to, f"正在切换到对话记录 {message}...") chat_info = CopilotGPT4.continue_chat( wx_id=wx_id, model=model, chat_index=int(message) ) diff --git a/wechatter/message/message_parser.py b/wechatter/message/message_parser.py index eebc03a..ee62461 100644 --- a/wechatter/message/message_parser.py +++ b/wechatter/message/message_parser.py @@ -6,7 +6,6 @@ import wechatter.config as config from wechatter.bot.bot_info import BotInfo from wechatter.models.message import Message, SendTo -from wechatter.notifier import Notifier class MessageHandler: @@ -41,9 +40,6 @@ def handle_message(self, message: Message) -> None: to = SendTo(message.source) # 是命令消息 - # 回复消息已收到 - Notifier.notify_received(to) - # 开始处理命令 cmd_handler = cmd_dict["handler"] if cmd_handler is not None: diff --git a/wechatter/notifier.py b/wechatter/notifier.py deleted file mode 100644 index 4644ef9..0000000 --- a/wechatter/notifier.py +++ /dev/null @@ -1,31 +0,0 @@ -# 消息通知器 -from wechatter.models.message import SendMessage, SendMessageType, SendTo -from wechatter.sender import Sender - - -class Notifier: - """消息通知器,用于发送非命令产生的消息""" - - def __init__(self): - pass - - # TODO: 改成只在为API请求的命令时才调用 - @staticmethod - def notify_received(to: SendTo) -> None: - """通知收到命令请求""" - msg = "收到命令请求" - Sender.send_msg(to, SendMessage(SendMessageType.TEXT, msg)) - - # 机器人登录登出通知,若是登录(登出)则发送登录(登出)消息给所有管理员 - @staticmethod - def notify_logged_in() -> None: - """通知登录成功""" - msg = "微信机器人启动成功" - Sender.send_msg_to_admins(msg) - - # FIXME: 登出消息发送不出去,因为发消息时候,机器人已经退出登录了 - @staticmethod - def notify_logged_out() -> None: - """通知已退出登录""" - msg = "微信机器人已退出" - Sender.send_msg_to_admins(msg) diff --git a/wechatter/sender/__init__.py b/wechatter/sender/__init__.py index 53f54e1..28ded72 100644 --- a/wechatter/sender/__init__.py +++ b/wechatter/sender/__init__.py @@ -1,3 +1,6 @@ +# isort: off from .sender import Sender +from .notifier import notify_logged_in, notify_logged_out, notify_received +# isort: on -__all__ = ["Sender"] +__all__ = ["Sender", "notify_received", "notify_logged_in", "notify_logged_out"] diff --git a/wechatter/sender/notifier.py b/wechatter/sender/notifier.py new file mode 100644 index 0000000..e7de822 --- /dev/null +++ b/wechatter/sender/notifier.py @@ -0,0 +1,23 @@ +# 消息通知器 +from wechatter.models.message import SendMessage, SendMessageType, SendTo +from wechatter.sender import Sender + + +def notify_received(to: SendTo) -> None: + """通知收到命令请求""" + msg = "收到命令请求" + Sender.send_msg(to, SendMessage(SendMessageType.TEXT, msg)) + + +# 机器人登录登出通知,若是登录(登出)则发送登录(登出)消息给所有管理员 +def notify_logged_in() -> None: + """通知登录成功""" + msg = "微信机器人启动成功" + Sender.send_msg_to_admins(msg) + + +# FIXME: 登出消息发送不出去,因为发消息时候,机器人已经退出登录了 +def notify_logged_out() -> None: + """通知已退出登录""" + msg = "微信机器人已退出" + Sender.send_msg_to_admins(msg)