Skip to content

Commit 5dda152

Browse files
author
Shanshui2024
committed
Merge branch 'AxTBot-v2' of https://github.com/AxT-Team/AxTBot into AxTBot-v2
2 parents 5e5d6ec + e1f6e0f commit 5dda152

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

utils/get_minecraft_info.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ async def check_server():
6868
return result
6969

7070

71-
7271
# ------------------快速设置------------------
73-
sv_api = "https://api.uapis.cn/minecraft/status?address="
72+
sv_api = "https://api.bluesdawn.top/minecraft/server/api?"
7473
error_no200 = "请求出错,请检查服务器是否在线!" # 请求失败时的提示
7574
error_notaprotocol = "请求出错,不是可用的类型!可用类型为java/be" # 当protocol字段不是java或be时的提示
7675
# ------------------快速设置结束-----------------
7776

7877
# ------------------主程序------------------
7978
async def get_mcserver_info(msg):
8079
# 消息分段处理
81-
address = msg.split()[1].split(':')[0]
80+
address = 'host=' + msg.split()[1].split(':')[0]
8281
port = '25565'
8382
if ':' in msg.split()[1]:
8483
port = msg.split()[1].split(':')[1]
@@ -95,9 +94,9 @@ async def get_mcserver_info(msg):
9594
# 使用aiohttp进行异步请求
9695
try:
9796
async with aiohttp.ClientSession() as session:
98-
async with session.get(url, timeout=15) as response: # type: ignore
97+
async with session.get(url, timeout=30) as response:
9998
if response.status == 200:
100-
data = await response.json()
99+
data = await response.json(content_type=None)
101100
return await create_text(data) # 构造消息
102101
else:
103102
return error_no200
@@ -111,10 +110,13 @@ async def get_mcserver_info(msg):
111110

112111
# ------------------构造消息------------------
113112
async def create_text(data):
114-
description = data['response'].get('description', '空')
115-
players_online = data['response']['players'].get('online', '未知')
116-
players_max = data['response']['players'].get('max', '未知')
117-
version = data['response']['version'].get('name', '未知')
113+
status = data['status']
114+
if status == 'Offline':
115+
return '''很抱歉,您所查询的服务器不在线!'''
116+
description = data['motd'].get('clean', '空')
117+
players_online = data['players'].get('online', '未知')
118+
players_max = data['players'].get('max', '未知')
119+
version = data['version'].get('version', '未知')
118120
if not isinstance(description, str):
119121
description = str(description)
120122
# 处理描述中的特殊字符和颜色代码(例如 §a, §c等)
@@ -129,4 +131,4 @@ async def create_text(data):
129131
{description}
130132
| 版本: {version}
131133
====================='''
132-
# ------------------构造完毕------------------
134+
# ------------------构造完毕------------------

0 commit comments

Comments
 (0)