Compare commits
2
Commits
8ad83d2a7e
...
db573b63bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db573b63bc | ||
|
|
5db68fd35f |
@@ -70,18 +70,18 @@ class bobbySession(requests.Session):
|
|||||||
for i in codes :
|
for i in codes :
|
||||||
res.append(i.group())
|
res.append(i.group())
|
||||||
return res
|
return res
|
||||||
def getInviteCode(self,step=0)->str:
|
def getInviteCode(self,ctx:str,step=0)->str:
|
||||||
if step == 5:
|
if step == 5:
|
||||||
raise SystemError("验证码查找失败")
|
raise SystemError("验证码查找失败")
|
||||||
try :
|
try :
|
||||||
codes = self.__getInvite()
|
codes = self.__getInvite()
|
||||||
if codes.__len__() == 0:
|
if codes.__len__() == 0:
|
||||||
self.__GenerateInvite()
|
self.__GenerateInvite()
|
||||||
return self.getInviteCode(step+1)
|
return self.getInviteCode(ctx,step+1)
|
||||||
rand =random.randrange(0,codes.__len__())
|
rand =random.randrange(0,codes.__len__())
|
||||||
return codes[rand]
|
return codes[rand]
|
||||||
except:
|
except:
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
return self.getInviteCode(step+1)
|
return self.getInviteCode(ctx,step+1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ from botpy.message import (Message,GroupMessage)
|
|||||||
from botpy.flags import (Flag,fill_with_flags)
|
from botpy.flags import (Flag,fill_with_flags)
|
||||||
from botpy import( logger,Intents,Client)
|
from botpy import( logger,Intents,Client)
|
||||||
from botpy.gateway import (BotWebSocket)
|
from botpy.gateway import (BotWebSocket)
|
||||||
from botpy.types.gateway import MessagePayload
|
from botpy.types.gateway import (MessagePayload)
|
||||||
import queue
|
import queue
|
||||||
from botpy.types.session import Session
|
from botpy.types.session import Session
|
||||||
|
from botpy.types.message import MarkdownPayload
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
import types
|
import types
|
||||||
@@ -16,6 +17,7 @@ from bobby import bobbySession
|
|||||||
from mcwatcher import watcher
|
from mcwatcher import watcher
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from serverGET import ServerGet
|
||||||
#环境配置
|
#环境配置
|
||||||
|
|
||||||
class Intents_ex(Intents):
|
class Intents_ex(Intents):
|
||||||
@@ -114,20 +116,23 @@ class djtuWebsocket (Client) :
|
|||||||
self.group_add(msg.group_openid)
|
self.group_add(msg.group_openid)
|
||||||
commands:dict[str,types.MethodType|types.FunctionType] = {
|
commands:dict[str,types.MethodType|types.FunctionType] = {
|
||||||
r'/邀请码' : bobby.getInviteCode,
|
r'/邀请码' : bobby.getInviteCode,
|
||||||
r'吃什么' : lambda :"是啊吃什么"
|
r'吃什么' : lambda ctx:"是啊吃什么" ,
|
||||||
|
r'/服务器' : ServerGet.GetNames,
|
||||||
}
|
}
|
||||||
required = msg.content
|
required = msg.content
|
||||||
reply = ""
|
reply = ""
|
||||||
for cmd,func in commands.items():
|
for cmd,func in commands.items():
|
||||||
if required.find(cmd) != -1:
|
if required.find(cmd) != -1:
|
||||||
try:
|
try:
|
||||||
reply = func()
|
ctx = required.split(cmd)[1]
|
||||||
|
reply = func(ctx)
|
||||||
except:
|
except:
|
||||||
reply = "服务异常"
|
reply = "服务异常"
|
||||||
break
|
break
|
||||||
if reply.__len__() == 0:
|
if reply.__len__() == 0:
|
||||||
reply = "你在发什么东西我怎么看不懂?"
|
reply = "你在发什么东西我怎么看不懂?"
|
||||||
await msg.reply(content=reply)
|
md = MarkdownPayload(content=reply)
|
||||||
|
await msg.reply(msg_type=2, markdown=md)
|
||||||
|
|
||||||
def group_add(self,gid :str):
|
def group_add(self,gid :str):
|
||||||
# 加入群聊
|
# 加入群聊
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
SECRET=""
|
||||||
|
APP_ID=""
|
||||||
|
BOBBY_PASSWORD=""
|
||||||
|
BOBBY_ACCOUNT=""
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import requests
|
||||||
|
from typing import List
|
||||||
|
class ServerGet :
|
||||||
|
url = r'https://mcserve-panel.hiso.de5.net/api/overview'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __getNames():
|
||||||
|
try:
|
||||||
|
res = requests.get(ServerGet.url)
|
||||||
|
data = res.json()
|
||||||
|
servers:list = data['servers']
|
||||||
|
return servers
|
||||||
|
except Exception as e :
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __getIndex(ind:int):
|
||||||
|
if ind <1 :
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
res = requests.get(ServerGet.url)
|
||||||
|
data = res.json()
|
||||||
|
servers:list = data['servers']
|
||||||
|
if ind>servers.__len__():
|
||||||
|
return None
|
||||||
|
server = servers[ind-1]
|
||||||
|
return server
|
||||||
|
except Exception as e :
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GetNames(ctx:str):
|
||||||
|
faultmsg = "(っ °Д °;)っ出错了呜....."
|
||||||
|
|
||||||
|
servers = ServerGet.__getNames()
|
||||||
|
if servers is None :
|
||||||
|
return faultmsg
|
||||||
|
if servers.__len__() == 0:
|
||||||
|
return "(っ °Д °;)っ好像...没有服务器呢"
|
||||||
|
|
||||||
|
# 试探是否有ctx对应的信息
|
||||||
|
try :
|
||||||
|
for s in servers:
|
||||||
|
if ctx.find(s['name']) != -1:
|
||||||
|
name = s['name']
|
||||||
|
s_id = s['id']
|
||||||
|
status = s['status']
|
||||||
|
online = s['online']
|
||||||
|
url = s['url']
|
||||||
|
addr = s['address']
|
||||||
|
|
||||||
|
msg = "{0} 信息如下:\n \nid: {1}\n状态: {2}\n在线人数: {3}\n信息页面: {4}\n地址: {5}".format(name,s_id,status,online,url,addr)
|
||||||
|
return msg
|
||||||
|
except:
|
||||||
|
'交给轮询试试'
|
||||||
|
# 服务器轮训
|
||||||
|
msg = 'mc服务器如下:\n \n'
|
||||||
|
try :
|
||||||
|
for i in servers:
|
||||||
|
msg += '' + """- <qqbot-cmd-input text="/服务器 {0}" show="{0}" reference="false" />""".format(str(i['name'])) +' ' + "状态:"+str(i['status'])
|
||||||
|
msg +='\n'
|
||||||
|
msg += ' \n点击蓝字获取详情~'
|
||||||
|
return msg
|
||||||
|
except:
|
||||||
|
return faultmsg
|
||||||
|
|
||||||
Reference in New Issue
Block a user