From c57ce4c543a1796cb905a462c1e0287193ca68ec Mon Sep 17 00:00:00 2001 From: Han Fangyuan Date: Fri, 24 Jan 2025 22:54:55 +0800 Subject: [PATCH] fix: remove group at auto reply plugin --- plugins/group_at_autoreply/README.md | 10 -- plugins/group_at_autoreply/__init__.py | 1 - .../group_at_autoreply/config.json.template | 6 - .../group_at_autoreply/group_at_autoreply.py | 119 ------------------ 4 files changed, 136 deletions(-) delete mode 100644 plugins/group_at_autoreply/README.md delete mode 100644 plugins/group_at_autoreply/__init__.py delete mode 100644 plugins/group_at_autoreply/config.json.template delete mode 100644 plugins/group_at_autoreply/group_at_autoreply.py diff --git a/plugins/group_at_autoreply/README.md b/plugins/group_at_autoreply/README.md deleted file mode 100644 index febd370a6..000000000 --- a/plugins/group_at_autoreply/README.md +++ /dev/null @@ -1,10 +0,0 @@ -## 插件说明 - -group_at_autoreply(群@时的自动回复) - -背景:有一些对外的技术支持群,下班后没有及时回复用户让用户心情不美丽,为了安抚用户,给用户一个心里预期,因此有了该功能。 -可以通过私聊AI助手,控制自动回复的开关和回复内容。 - -## 插件使用 - -在私聊中可使用`$群自动回复`指令查看详细说明。 diff --git a/plugins/group_at_autoreply/__init__.py b/plugins/group_at_autoreply/__init__.py deleted file mode 100644 index 39a37999f..000000000 --- a/plugins/group_at_autoreply/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .group_at_autoreply import * diff --git a/plugins/group_at_autoreply/config.json.template b/plugins/group_at_autoreply/config.json.template deleted file mode 100644 index 7b7c99f2e..000000000 --- a/plugins/group_at_autoreply/config.json.template +++ /dev/null @@ -1,6 +0,0 @@ -{ - "zexin.li": { - "enabled": false, - "reply_text": "干饭去了,稍后找他~" - } -} \ No newline at end of file diff --git a/plugins/group_at_autoreply/group_at_autoreply.py b/plugins/group_at_autoreply/group_at_autoreply.py deleted file mode 100644 index 49dbfc652..000000000 --- a/plugins/group_at_autoreply/group_at_autoreply.py +++ /dev/null @@ -1,119 +0,0 @@ -import plugins -from bridge.context import ContextType -from bridge.reply import Reply, ReplyType -from plugins import * - - -@plugins.register( - name="GroupAtAutoreply", - desire_priority=0, - hidden=True, - enabled=False, - desc="群聊中出现@某人时,触发某人的自动回复", - version="0.1", - author="zexin.li", -) -class GroupAtAutoreply(Plugin): - - def __init__(self): - super().__init__() - try: - self.config = super().load_config() - if self.config is None: - self.config = {} - config_path = os.path.join(os.path.dirname(__file__), "config.json") - with open(config_path, "w") as f: - json.dump(self.config, f, indent=4) - logger.info("[GroupAtAutoreply] inited") - self.handlers[Event.ON_RECEIVE_MESSAGE] = self.on_receive_message - self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context - except Exception as e: - logger.error(f"[GroupAtAutoreply]初始化异常:{e}") - raise "[GroupAtAutoreply] init failed, ignore " - - def _update_config(self, username, enabled, reply_text): - new_config = { - "enabled": enabled, - "reply_text": reply_text if reply_text else "" - } - self.config[username] = new_config - self.save_config(self.config) - - # 收到消息的时候,直接判断是否需要自动回复,需要的话,直接准备好,放在 context - def on_receive_message(self, e_context: EventContext): - if self.config is None: - return - - context = e_context["context"] - if context.type != ContextType.TEXT: - return - - if context.get("isgroup", False): - # 群聊消息,检测是否触发了自动回复 - autoreply_members = [] - if isinstance(context["msg"].at_list, list): - for at in context["msg"].at_list: - if at in self.config: - at_config = self.config[at] - if at_config["enabled"]: - autoreply_members.append(at) - - if len(autoreply_members) > 0: - context["autoreply_members"] = autoreply_members - e_context.action = EventAction.BREAK_PASS - elif str(context.content).startswith("$群自动回复"): - # 私聊消息,且是设置自动回复的 - lines = str(context.content).split("\n")[1:] - enabled = None # 开关 - reply_text = None # 回复内容 - - for line in lines: - line = line.strip() - index = line.find(":") - if index == -1: - index = line.find(":") - if index == -1: - continue - key = line[:index].strip() - value = line[index + 1:].strip() - if key == "开关": - enabled = True if "打开" == value else (False if "关闭" == value else None) - elif key == "回复内容": - reply_text = value - - help_info = "指令错误,参考示例如下:\n\n$群自动回复\n开关: 打开\n回复内容: 请稍后联系~\n\n$群自动回复\n开关: 关闭" - if enabled is None: - autoreply_config_result = help_info - elif enabled and reply_text is None: - autoreply_config_result = help_info - else: - cmsg = context["msg"] - username = cmsg.from_user_nickname - self._update_config(username, enabled, reply_text) - autoreply_config_result = f"群自动回复,已{'开启' if enabled else '关闭'}" - - context["autoreply_config_result"] = autoreply_config_result - e_context.action = EventAction.BREAK_PASS - - def on_handle_context(self, e_context: EventContext): - context = e_context["context"] - reply_text = None - if "autoreply_members" in context: - autoreply_members = context["autoreply_members"] - if autoreply_members is None or len(autoreply_members) == 0: - return - - reply_text = "" - for member in autoreply_members: - member_config = self.config[member] - if member_config["enabled"]: - reply_text += f"\n{member}自动回复:{member_config['reply_text']}" - elif "autoreply_config_result" in context: - reply_text = context["autoreply_config_result"] - - if reply_text is not None: - reply = Reply() - reply.type = ReplyType.TEXT - reply.content = reply_text - e_context["reply"] = reply - e_context.action = EventAction.BREAK_PASS