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, Feature, PermissionStatus class GroupAdd: def __init__(self, wcf: Wcf, gbm: GroupBotManager, all_contacts: dict): # 读取配置文件 with open("group_add/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 # 如果触发了指令,但是没有权限,则返回权限不足 if self.gbm.get_group_permission(message.roomid, Feature.GROUP_ADD) == PermissionStatus.DISABLED: return now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) nick_name = self.all_contacts.get(message.sender, message.sender) # 创建包含用户昵称、时间和Emoji表情的字符串 welcome_message = f"🎉 欢迎用户 {nick_name} \n👋 在 {now_time} 🕒 加入群聊!😊" self.wcf.send_text(welcome_message, (message.roomid if message.from_group() else message.sender), message.sender)