feature:1.加群功能插件化;2.成员变更不监听消息,使用定时检查策略;

This commit is contained in:
liuwei
2025-03-20 14:23:09 +08:00
parent ce837d241a
commit 333a87e34c
15 changed files with 584 additions and 358 deletions
+3 -49
View File
@@ -22,10 +22,7 @@ from base.func_xinghuo_web import XinghuoWeb
from base.func_claude import Claude
from configuration import Config
from constants import ChatType
from game_task.game_task_encyclopedia import game_process_message, get_group_ids,run_random_task_assignment
from group_add.main import GroupAdd
from group_auto.group_auto_invite import get_first_group_id, process_command
from group_auto.group_member_change import GroupMemberChange
from game_task.game_task_encyclopedia import game_process_message, get_group_ids, run_random_task_assignment
from message_storage.message_to_db import MessageStorage
from plugin_common.event_system import EventType, EventSystem
from plugin_common.message_plugin_interface import MessagePluginInterface
@@ -41,14 +38,13 @@ __version__ = "39.2.4.0"
from sehuatang.shehuatang import pdf_file_path
from xiuren.meitu_dl import meitu_dowload_pub_pic
from xiuren.random_pic import get_xiuren_heisi_pic
from xiuren.xiuren_pdf import generate_pdf_from_images
from db.connection import DBConnectionManager
from message_util import MessageUtil
# 在文件顶部导入装饰器
from job_decorators import scheduled_job, register_scheduled_jobs
from job_decorators import register_scheduled_jobs
class Robot(Job):
@@ -109,11 +105,6 @@ class Robot(Job):
# 消息存档模块初始化,自动完成入库动作
self.message_storage = MessageStorage()
# 群成员变更模块加载
self.gmc = GroupMemberChange(wcf, self.redis_pool)
# 加群测试
self.group_add = GroupAdd(wcf, self.gbm)
# 在初始化结束时注册所有被装饰的定时任务
register_scheduled_jobs(self)
if ChatType.is_in_chat_types(chat_type):
@@ -180,10 +171,6 @@ class Robot(Job):
# 去除@的人和空格等字符
q = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "")
# 使用正则表达式匹配加群指令
pattern = r'#加群:\[(.*?)\]' # 匹配 #加群:[<任何内容>]
match = re.match(pattern, q)
# 所有人员都可以要求他撤回刚刚的信息
if msg.from_group() and q.startswith("/"):
# 进行权限判断 加入权限,防止tokens浪费
@@ -210,15 +197,6 @@ class Robot(Job):
elif q in ["nbc", "cnn", "abc", "fox", "bbc"]:
self.news_en_report(q, (msg.roomid if msg.from_group() else msg.sender))
return True
# 如果正则匹配到时加群指令,则从库中提取第一个群ID
elif match:
try:
group_id = get_first_group_id(match.group(1))
self.LOG.info(f"邀请加入{match.group(1)}群,ID{group_id}{msg.sender}")
self.wcf.invite_chatroom_members(group_id, msg.sender)
except Exception as e:
self.LOG.error(f"邀请加入群出错:{e}")
return True
else:
# 如果是群消息,并且群没开启AI,则不处理该动作
if msg.from_group() and self.gbm.get_group_permission(msg.roomid,
@@ -267,7 +245,6 @@ class Robot(Job):
# 聊天记录入库动作:
try:
self.message_storage.archive_message(msg)
# self.LOG.info(f"msg.xml:{msg.xml}")
except Exception as e:
self.LOG.error(f"archive_message error: {e}")
@@ -301,18 +278,6 @@ class Robot(Job):
return
except Exception as e:
self.LOG.error(f"game_message_load error{e}")
try:
# if msg.type == 10000:
# self.LOG.info(msg)
# self.group_add.handle_message(msg)
# return
result = self.gmc.process_message(msg.roomid, msg.xml)
# 判断是否没有变化
if "$NO_CHANGE$" not in result:
self.LOG.info(f"检测到群成员变化,进行相关内容输出:{result}")
self.send_text_msg(result, msg.roomid)
except Exception as e:
self.LOG.error(f"group_member_change error: {e}")
if msg.is_at(self.wxid): # 被@
self.toAt(msg)
@@ -337,18 +302,6 @@ class Robot(Job):
self.news_baidu_report()
if msg.content.startswith("清除群-"):
self.gbm.handle_command(msg.roomid, msg.content)
if msg.content == 'GROUP_LIST':
self.send_text_msg(self.gbm.get_group_list(), msg.sender)
if msg.content.startswith('#加群配置'):
# msg_content = "# 加群配置|add 原生鱼 xxx@room"
parts = msg.content.split('|')
resp = ""
if len(parts) > 1:
after_pipe = parts[1]
resp = process_command(after_pipe)
else:
resp = process_command("help")
self.send_text_msg(resp, msg.sender)
self.send_text_msg(f"指令:{msg.content} 已执行", msg.sender)
else:
self.toChitchat(msg) # 闲聊
@@ -564,6 +517,7 @@ class Robot(Job):
self.send_text_msg(output, r)
except Exception as e:
self.LOG.error(f"SendRanking error{e}")
# 设置定时任务
def game_auto_tasks(self):
try: