import logging import re 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): # 读取配置文件 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.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 = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 使用正则表达式提取双引号中的内容 match = re.search(r'"(.*?)"', message.content) if match: nickname = match.group(1) welcome_message = f"🎉 欢迎 【{nickname}】 加入群聊👋 \n 🕒 {now_time} 🕒 !" self.wcf.send_text(welcome_message, message.roomid) else: print("未找到昵称信息!")