feat : mcwatcher 广播
This commit is contained in:
@@ -95,7 +95,6 @@ class djtuWebsocket (Client) :
|
|||||||
logger.warning("data解析失败")
|
logger.warning("data解析失败")
|
||||||
return
|
return
|
||||||
logger.info("入群信息:"+' 群: '+openid+" openid: "+memberid)
|
logger.info("入群信息:"+' 群: '+openid+" openid: "+memberid)
|
||||||
print("palayload"+str(payload))
|
|
||||||
await self.api.post_group_message(openid,event_id=eid,content='欢迎加入大海啸!\n入服教程请看链接:\nhttps://starptr.top')
|
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):
|
async def parseGlobalMessage(self,payload):
|
||||||
print(payload)
|
|
||||||
try :
|
try :
|
||||||
msg = payload['d']
|
msg = payload['d']
|
||||||
gid = msg['group_id']
|
gid = msg['group_id']
|
||||||
content = msg['content']
|
content = msg['content']
|
||||||
except:
|
except:
|
||||||
return
|
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] = {
|
commands:dict[str,types.MethodType|types.FunctionType] = {
|
||||||
r'吃什么' : lambda :"是啊吃什么"
|
r'吃什么' : lambda :"是啊吃什么"
|
||||||
}
|
}
|
||||||
@@ -150,12 +157,12 @@ class djtuWebsocket (Client) :
|
|||||||
# time.sleep会阻塞整个线程我去
|
# time.sleep会阻塞整个线程我去
|
||||||
await asyncio.sleep(20)
|
await asyncio.sleep(20)
|
||||||
else:
|
else:
|
||||||
|
# 广播
|
||||||
try :
|
try :
|
||||||
msg = self.q.get()
|
msg = self.q.get()
|
||||||
if group_open_id is None:
|
for i in groups:
|
||||||
logger.error("群聊不存在")
|
|
||||||
continue
|
asyncio.create_task(self.api.post_group_message(i,content=msg))
|
||||||
asyncio.create_task(self.api.post_group_message(group_open_id,content=msg))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("MCWatcher发送群聊任务失败:\n"+str(e))
|
logger.error("MCWatcher发送群聊任务失败:\n"+str(e))
|
||||||
|
|
||||||
@@ -166,8 +173,7 @@ bbyAccount = os.getenv("BOBBY_ACCOUNT")
|
|||||||
bbyPasswd = os.getenv("BOBBY_PASSWORD")
|
bbyPasswd = os.getenv("BOBBY_PASSWORD")
|
||||||
appid = os.getenv("APP_ID")
|
appid = os.getenv("APP_ID")
|
||||||
secret_bot = os.getenv("SECRET")
|
secret_bot = os.getenv("SECRET")
|
||||||
group_open_id = os.getenv("GROUP_OPEN_ID")
|
groups:list[str] = []
|
||||||
dev = os.getenv("DEV")
|
|
||||||
|
|
||||||
if appid is None or secret_bot is None :
|
if appid is None or secret_bot is None :
|
||||||
raise SystemExit("未找到bot配置!")
|
raise SystemExit("未找到bot配置!")
|
||||||
|
|||||||
Reference in New Issue
Block a user