From 9cef559a05df431c3ff0ad9f7e1b8649f50661a6 Mon Sep 17 00:00:00 2001 From: lanvent Date: Thu, 13 Apr 2023 10:50:18 +0800 Subject: [PATCH] feat: support receive_message event --- channel/chat_channel.py | 10 +++++++--- plugins/event.py | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index eb64cfc..5ed0886 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -48,9 +48,6 @@ class ChatChannel(Channel): if first_in: # context首次传入时,receiver是None,根据类型设置receiver config = conf() cmsg = context['msg'] - if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', True): - logger.debug("[WX]self message skipped") - return None if context.get("isgroup", False): group_name = cmsg.other_user_nickname group_id = cmsg.other_user_id @@ -69,6 +66,13 @@ class ChatChannel(Channel): else: context['session_id'] = cmsg.other_user_id context['receiver'] = cmsg.other_user_id + e_context = PluginManager().emit_event(EventContext(Event.ON_RECEIVE_MESSAGE, {'channel': self, 'context': context})) + context = e_context['context'] + if e_context.is_pass() or context is None: + return context + if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', True): + logger.debug("[WX]self message skipped") + return None # 消息内容匹配过程,并处理content if ctype == ContextType.TEXT: diff --git a/plugins/event.py b/plugins/event.py index a65e548..a11a4ab 100644 --- a/plugins/event.py +++ b/plugins/event.py @@ -4,7 +4,10 @@ from enum import Enum class Event(Enum): - # ON_RECEIVE_MESSAGE = 1 # 收到消息 + ON_RECEIVE_MESSAGE = 1 # 收到消息 + """ + e_context = { "channel": 消息channel, "context" : 本次消息的context} + """ ON_HANDLE_CONTEXT = 2 # 处理消息前 """