feat : mcwatcher 广播
This commit is contained in:
@@ -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配置!")
|
||||
|
||||
Reference in New Issue
Block a user