From cd298aaacd6536d02a5aaf60699ac8525ffd07f6 Mon Sep 17 00:00:00 2001 From: HexatomicRing <54496918+HexatomicRing@users.noreply.github.com> Date: Thu, 15 May 2025 12:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8B=92=E6=94=B6=E6=88=B3?= =?UTF-8?q?=E4=B8=80=E6=88=B3=E5=92=8C=E8=87=AA=E5=8A=A8=E6=88=B3=E5=9B=9E?= =?UTF-8?q?=E5=8E=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.py | 3 +++ src/recv_handler.py | 31 +++++++++++++++++++++++++------ template/template_config.toml | 5 +++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/config.py b/src/config.py index 3be3d5a..8f32144 100644 --- a/src/config.py +++ b/src/config.py @@ -47,6 +47,9 @@ class Config: self.mai_port = raw_config["MaiBot_Server"].get("port", 8000) self.debug_level = raw_config["Debug"].get("level", "INFO") self.use_tts = raw_config["Voice"].get("use_tts", False) + self.notify_enable = raw_config["Notify"].get("enable", True) + self.notify_auto_group = raw_config["Notify"].get("auto_group", False) + self.notify_auto_friend = raw_config["Notify"].get("auto_friend", False) else: logger.error("配置文件不存在!") logger.info("正在创建配置文件...") diff --git a/src/recv_handler.py b/src/recv_handler.py index 053c9d4..9ec150b 100644 --- a/src/recv_handler.py +++ b/src/recv_handler.py @@ -20,6 +20,7 @@ from maim_message import ( Router, ) +from .send_handler import send_handler from .utils import ( get_group_info, get_member_info, @@ -467,7 +468,7 @@ class RecvHandler: logger.warning("不支持的notice类型") return None if not handled_message: - logger.warning("notice处理失败或不支持") + logger.warning("notice处理失败或被跳过") return None source_name: str = None @@ -533,13 +534,31 @@ class RecvHandler: return None self_id = raw_message.get("self_id") target_id = raw_message.get("target_id") - target_name: str = None + if self_id != target_id: # 不响应别人戳别人 + return None + sender_id = raw_message.get("sender_id") + group_id = raw_message.get("group_id") + user_id = raw_message.get("user_id") + if group_id and global_config.notify_auto_group: + await send_handler.send_message_to_napcat( + action="group_poke", + params={ + "group_id": group_id, + "user_id": user_id + } + ) + if sender_id and global_config.notify_auto_friend: + await send_handler.send_message_to_napcat( + action="friend_poke", + params={ + "user_id": user_id + } + ) + if not global_config.notify_enable: + return None raw_info: list = raw_message.get("raw_info") # 计算Seg - if self_id == target_id: - target_name = self_info.get("nickname") - else: - return None + target_name: str = self_info.get("nickname") try: first_txt = raw_info[2].get("txt", "戳了戳") second_txt = raw_info[4].get("txt", "") diff --git a/template/template_config.toml b/template/template_config.toml index f03a12c..5f8b32f 100644 --- a/template/template_config.toml +++ b/template/template_config.toml @@ -16,6 +16,11 @@ group_list = [] private_list = [] enable_temp = false +[Notify] # 戳一戳响应 +enable = true # 是否将戳一戳转化为文本 +auto_group = false # 群聊自动戳回去 +auto_friend = false # 私聊自动戳回去 + [Voice] # 发送语音设置 use_tts = false # 是否使用tts语音(请确保你配置了tts并有对应的adapter)