From 9cb81deab463092b018dc65ceaa5abd184cb60c4 Mon Sep 17 00:00:00 2001 From: Wbucket <2595141012@stu.hqu.edu.cn> Date: Wed, 30 Sep 2026 21:18:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20mcwatcher=20=E5=B9=BF=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 13f507f..b1b7d61 100644 --- a/bot.py +++ b/bot.py @@ -95,7 +95,6 @@ class djtuWebsocket (Client) : logger.warning("data解析失败") return logger.info("入群信息:"+' 群: '+openid+" openid: "+memberid) - print("palayload"+str(payload)) await self.api.post_group_message(openid,event_id=eid,content='欢迎加入大海啸!\n入服教程请看链接:\nhttps://starptr.top') # 触发概率不大所以可以直接提取关键字 @@ -119,13 +118,21 @@ class djtuWebsocket (Client) : # 触发概率大,以后要做好解析防止刷屏 async def parseGlobalMessage(self,payload): - print(payload) try : msg = payload['d'] gid = msg['group_id'] content = msg['content'] except: return + # 加入群聊 + new_group = True + if not groups is None : + for i in groups : + if i.find(gid) != -1 : + new_group = False + if new_group : + groups.append(gid) + # 解析指令 commands:dict[str,types.MethodType|types.FunctionType] = { r'吃什么' : lambda :"是啊吃什么" } @@ -150,12 +157,12 @@ class djtuWebsocket (Client) : # time.sleep会阻塞整个线程我去 await asyncio.sleep(20) else: + # 广播 try : msg = self.q.get() - if group_open_id is None: - logger.error("群聊不存在") - continue - asyncio.create_task(self.api.post_group_message(group_open_id,content=msg)) + for i in groups: + + asyncio.create_task(self.api.post_group_message(i,content=msg)) except Exception as e: logger.error("MCWatcher发送群聊任务失败:\n"+str(e)) @@ -166,8 +173,7 @@ bbyAccount = os.getenv("BOBBY_ACCOUNT") bbyPasswd = os.getenv("BOBBY_PASSWORD") appid = os.getenv("APP_ID") secret_bot = os.getenv("SECRET") -group_open_id = os.getenv("GROUP_OPEN_ID") -dev = os.getenv("DEV") +groups:list[str] = [] if appid is None or secret_bot is None : raise SystemExit("未找到bot配置!")