feature:加入了群成员变化监控功能,提醒群成员,有人退出了群聊

This commit is contained in:
liuwei
2025-02-18 17:57:29 +08:00
parent 6c8147cb17
commit 48a36d42d4
3 changed files with 276 additions and 6 deletions

View File

@@ -24,6 +24,8 @@ from base.func_xinghuo_web import XinghuoWeb
from base.func_claude import Claude
from configuration import Config
from constants import ChatType
from group_auto.group_auto_invite import get_first_group_id
from group_auto.group_member_change import GroupMemberChange
from robot_cmd.robot_command import GroupBotManager
from job_mgmt import Job
from robot_cmd.robot_command import Feature
@@ -51,6 +53,7 @@ class Robot(Job):
self.groups = {} # 存储按group_id分组的消息列表每个group_id最多保留10条消息
GroupBotManager.load_local_cache()
self.gbm = GroupBotManager()
self.gmc = GroupMemberChange(wcf)
if ChatType.is_in_chat_types(chat_type):
if chat_type == ChatType.TIGER_BOT.value and TigerBot.value_check(self.config.TIGERBOT):
self.chat = TigerBot(self.config.TIGERBOT)
@@ -138,25 +141,32 @@ class Robot(Job):
else: # 接了 ChatGPT智能回复
# 去除@的人和空格等字符
q = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "")
# 使用正则表达式匹配加群指令
pattern = r'#加群:\[(.*?)\]' # 匹配 #加群:[<任何内容>]
match = re.match(pattern, q)
# 所有人员都可以要求他撤回刚刚的信息
if q == '撤回':
self.revoke_messages(msg.roomid)
return True
if q == "今日百度新闻":
if q == "#今日百度新闻":
self.newsBaiduReport((msg.roomid if msg.from_group() else msg.sender))
return True
elif q in ["nbc", "cnn", "abc", "fox", "bbc"]:
self.newsEnReport(q, (msg.roomid if msg.from_group() else msg.sender))
return True
elif q == '/总结':
elif q == '#总结':
self.message_summary_robot((msg.roomid if msg.from_group() else msg.sender))
return True
elif q == '4K':
# 如果正则匹配到时加群指令则从库中提取第一个群ID
elif match:
try:
self.LOG.info(f"邀请加入4K群{msg.sender}")
self.wcf.invite_chatroom_members('45317011307@chatroom', msg.sender)
group_id = get_first_group_id(match.group(1))
self.LOG.info(f"邀请加入{match.group(1)}{msg.sender}")
self.wcf.invite_chatroom_members(group_id, msg.sender)
except Exception as e:
self.LOG.error(f"邀请加入4K群出错:{e}")
self.LOG.error(f"邀请加入群出错:{e}")
return True
else:
# 如果是群消息并且群没开启AI则不处理该动作
@@ -214,6 +224,15 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"revoke_receive_message error: {e}")
try:
result = self.gmc.process_message(msg.roomid, msg.xml)
# 判断是否没有变化
if "$NO_CHANGE$" not in result:
self.LOG.info(f"检测到群成员变化,进行相关内容输出:{result}")
self.sendTextMsg(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)