mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-16 09:38:52 +00:00
speed_test 支持查询附近 测速点列表
This commit is contained in:
parent
3d883f7e4a
commit
1a13ed75d5
@ -342,7 +342,7 @@
|
||||
},
|
||||
{
|
||||
"name": "speed_test",
|
||||
"version": "1.0",
|
||||
"version": "1.002",
|
||||
"section": "chat",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "3.02 kb",
|
||||
|
@ -65,13 +65,28 @@ async def run_speedtest(message: Message):
|
||||
return des, "speedtest.png" if exists("speedtest.png") else None
|
||||
|
||||
|
||||
async def get_all_ids():
|
||||
test = Speedtest()
|
||||
servers = test.get_closest_servers()
|
||||
if not servers:
|
||||
return "附近没有测速点", None
|
||||
return "附近的测速点有:\n\n" + \
|
||||
"\n".join(f"`{i['id']}` - `{int(i['d'])}km` - `{i['name']}` - `{i['sponsor']}`" for i in servers), None
|
||||
|
||||
|
||||
@listener(command="speedtest",
|
||||
description=lang('speedtest_des'),
|
||||
parameters="(Server ID)")
|
||||
parameters="(Server ID/测速点列表)")
|
||||
async def speedtest(message: Message):
|
||||
""" Tests internet speed using speedtest. """
|
||||
msg = await message.edit(lang('speedtest_processing'))
|
||||
if message.arguments == "测速点列表":
|
||||
msg = message
|
||||
else:
|
||||
msg: Message = await message.edit(lang('speedtest_processing'))
|
||||
try:
|
||||
if message.arguments == "测速点列表":
|
||||
des, photo = await get_all_ids()
|
||||
else:
|
||||
des, photo = await run_speedtest(message)
|
||||
except SpeedtestHTTPError:
|
||||
return await msg.edit(lang('speedtest_ConnectFailure'))
|
||||
@ -87,4 +102,5 @@ async def speedtest(message: Message):
|
||||
await message.bot.send_photo(message.chat.id, photo, caption=des)
|
||||
except Exception:
|
||||
return await msg.edit(des)
|
||||
await msg.safe_delete()
|
||||
safe_remove(photo)
|
||||
|
Loading…
Reference in New Issue
Block a user