调整入库逻辑,@指令通过dify 触发,让AI逻辑在一起。
This commit is contained in:
27
robot.py
27
robot.py
@@ -154,13 +154,6 @@ class Robot(Job):
|
||||
return all(value is not None for key, value in args.items() if key != 'proxy')
|
||||
return False
|
||||
|
||||
def toAt(self, msg: WxMsg) -> bool:
|
||||
"""处理被 @ 消息
|
||||
:param msg: 微信消息结构
|
||||
:return: 处理状态,`True` 成功,`False` 失败
|
||||
"""
|
||||
return self.toChitchat(msg)
|
||||
|
||||
def toChitchat(self, msg: WxMsg) -> bool:
|
||||
"""闲聊,接入 ChatGPT
|
||||
"""
|
||||
@@ -210,12 +203,14 @@ class Robot(Job):
|
||||
# 发布消息接收事件
|
||||
self.event_system.publish(EventType.MESSAGE_RECEIVED, {"message": msg})
|
||||
|
||||
# 标记插件是否处理了消息
|
||||
plugin_processed = False
|
||||
|
||||
# 尝试使用插件处理消息
|
||||
if self.process_plugin_message(msg):
|
||||
return
|
||||
plugin_processed = True
|
||||
|
||||
# 如果没有插件处理,使用原有逻辑处理消息
|
||||
# 群聊消息
|
||||
# 群聊消息处理 - 无论插件是否处理过,都执行数据存储
|
||||
if msg.from_group():
|
||||
# 调用统计逻辑进行聊天数据统计:
|
||||
try:
|
||||
@@ -232,6 +227,10 @@ class Robot(Job):
|
||||
except Exception as e:
|
||||
self.LOG.error(f"archive_message error: {e}")
|
||||
|
||||
# 如果插件已处理消息,则不再执行后续的业务逻辑
|
||||
if plugin_processed:
|
||||
return
|
||||
|
||||
# 记录在群里发的最新消息,可以通过撤回指令撤回
|
||||
try:
|
||||
if msg.from_self():
|
||||
@@ -243,10 +242,12 @@ class Robot(Job):
|
||||
except Exception as e:
|
||||
self.LOG.error(f"revoke_receive_message error: {e}")
|
||||
|
||||
if msg.is_at(self.wxid): # 被@
|
||||
self.toAt(msg)
|
||||
return # 处理完群聊信息,后面就不需要处理了
|
||||
|
||||
# 如果插件已处理消息,则不再执行后续的业务逻辑
|
||||
if plugin_processed:
|
||||
return
|
||||
|
||||
# 非群聊信息,按消息类型进行处理
|
||||
if msg.type == 37: # 好友请求
|
||||
self.LOG.info(f"收到好友请求:{msg}")
|
||||
@@ -421,7 +422,7 @@ class Robot(Job):
|
||||
"sender": msg.sender,
|
||||
"roomid": msg.roomid if msg.from_group() else "",
|
||||
"xml": msg.xml,
|
||||
"is_at": msg.is_at(self.wxid),
|
||||
"is_at": msg.is_at(self.wxid), # 确保正确设置is_at标志
|
||||
"timestamp": time.time(),
|
||||
"wcf": self.wcf, # 提供wcf对象,让插件可以直接发送消息
|
||||
"message_util": self.message_util, # 提供消息工具类
|
||||
|
||||
Reference in New Issue
Block a user