forked from TeamUltroid/UltroidAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
96 lines (85 loc) · 2.5 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Ported From DarkCobra Originally By UNIBORG
#
# Ultroid - UserBot
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}test`
Test Your Server Speed.
"""
from datetime import datetime
import speedtest
from . import *
@ultroid_cmd(pattern="test ?(.*)")
async def _(event):
input_str = event.pattern_match.group(1)
as_document = None
if input_str == "image":
as_document = False
elif input_str == "file":
as_document = True
xx = await event.eor("`Calculating ur Ultroid Server Speed. Please wait!`")
start = datetime.now()
s = speedtest.Speedtest()
s.get_best_server()
s.download()
s.upload()
end = datetime.now()
ms = (end - start).seconds
response = s.results.dict()
download_speed = response.get("download")
upload_speed = response.get("upload")
ping_time = response.get("ping")
client_infos = response.get("client")
i_s_p = client_infos.get("isp")
i_s_p_rating = client_infos.get("isprating")
reply_msg_id = event.message.id
if event.reply_to_msg_id:
reply_msg_id = event.reply_to_msg_id
try:
response = s.results.share()
speedtest_image = response
if as_document is None:
await xx.edit(
"""`Ultroid Server Speed in {} sec`
`Download: {}`
`Upload: {}`
`Ping: {}`
`Internet Service Provider: {}`
`ISP Rating: {}`""".format(
ms,
humanbytes(download_speed),
humanbytes(upload_speed),
ping_time,
i_s_p,
i_s_p_rating,
)
)
else:
await event.client.send_file(
event.chat_id,
speedtest_image,
caption="**SpeedTest** completed in {} seconds".format(ms),
force_document=as_document,
reply_to=reply_msg_id,
allow_cache=False,
)
await event.delete()
except Exception as exc: # dc
await xx.edit(
"""**SpeedTest** completed in {} seconds
Download: {}
Upload: {}
Ping: {}
__With the Following ERRORs__
{}""".format(
ms,
humanbytes(download_speed),
humanbytes(upload_speed),
ping_time,
str(exc),
)
)