From a7de9b2eb4ac5e7544fee6702beb367e497a3798 Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 10 Mar 2025 14:52:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E7=BE=A4=E6=B6=88=E6=81=AF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group_add/config.toml | 2 + group_add/main.py | 90 +++++++++++++++++++++++++++++++++++++++++++ robot.py | 6 +++ 3 files changed, 98 insertions(+) create mode 100644 group_add/config.toml create mode 100644 group_add/main.py diff --git a/group_add/config.toml b/group_add/config.toml new file mode 100644 index 0000000..0dd36a3 --- /dev/null +++ b/group_add/config.toml @@ -0,0 +1,2 @@ +[GroupAdd] +enable = true diff --git a/group_add/main.py b/group_add/main.py new file mode 100644 index 0000000..94c829a --- /dev/null +++ b/group_add/main.py @@ -0,0 +1,90 @@ +import logging +from datetime import datetime + +import mysql.connector.pooling +import tomllib +import redis +from wcferry import Wcf, WxMsg + +from robot_cmd.robot_command import GroupBotManager + + +class GroupAdd: + def __init__(self, wcf: Wcf, gbm: GroupBotManager, all_contacts: dict): + # 读取配置文件 + with open("group_video_man/config.toml", "rb") as f: + plugin_config = tomllib.load(f) + + config = plugin_config["GroupAdd"] + self.LOG = logging.getLogger(__name__) + + self.enable = config["enable"] + self.wcf = wcf + self.gbm = gbm + self.all_contacts = all_contacts + + self.LOG.info(f"[加群提醒] 组件初始化完成") + + def handle_message(self, message: WxMsg): + if not self.enable: + return + now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + nick_name = self.all_contacts.get(message.sender, message.sender) + + user_info = self.wcf.query_sql("MicroMsg.db", f"SELECT * FROM Contact WHERE UserName = '{message.sender}';") + + self.LOG.info(f"GroupAdd contact:{user_info}") + + BigHeadImgUrl = "" + url = "https://hot.imsyy.top/#/" + outxml = f""" + + + + 👏欢迎 {nick_name} 加入群聊!🎉 + ⌚时间:{now_time} + view + 5 + 0 + + {url} + + + + + {BigHeadImgUrl} + + + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + + Jyunere + 0 + + 1 + + + + + + """ diff --git a/robot.py b/robot.py index bf035a1..d6412fc 100644 --- a/robot.py +++ b/robot.py @@ -29,6 +29,7 @@ from configuration import Config from constants import ChatType from game_task.game_task_encyclopedia import game_process_message, setup_schedule, 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 group_video.bot_video import BotVideo @@ -96,6 +97,8 @@ class Robot(Job): self.xiuren = Xiuren(wcf, self.gbm) # 美腿模块 self.beautyleg = BeautyLeg(wcf, self.gbm) + # 加群测试 + self.group_add = GroupAdd(wcf, self.gbm, self.allContacts) if ChatType.is_in_chat_types(chat_type): if chat_type == ChatType.TIGER_BOT.value and TigerBot.value_check(self.config.TIGERBOT): @@ -321,6 +324,9 @@ class Robot(Job): self.LOG.error(f"game_message_load error:{e}") try: # TODO 群人员添加也是消息类型10000的消息 + if msg.type == 10000: + self.group_add.handle_message(msg) + result = self.gmc.process_message(msg.roomid, msg.xml) # 判断是否没有变化 if "$NO_CHANGE$" not in result: