-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspeedtest.py
50 lines (38 loc) · 1.92 KB
/
speedtest.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
# Sh1t-UB (telegram userbot by sh1tn3t)
# Copyright (C) 2021-2022 Sh1tN3t
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# required: speedtest-cli
import speedtest
from pyrogram import Client, types
from .. import loader, utils
def speed_test():
tester = speedtest.Speedtest()
tester.get_best_server()
tester.download()
tester.upload()
return tester.results.dict()
@loader.module(name="SpeedTest", author="sh1tn3t")
class SpeedTestMod(loader.Module):
"""Тест интернет-соединения"""
async def speedtest_cmd(self, app: Client, message: types.Message):
"""Запускает тест скорости. Использование: speedtest"""
await utils.answer(
message, "<b>Запускаем тест...</b>")
result = speed_test()
text = (
f"<b>Результаты теста:</b>\n\n"
f"<b>Скачивание:</b> <code>{round(result['download'] / 2 ** 20 / 8, 2)}</code> <b>мб/с</b>\n"
f"<b>Загрузка:</b> <code>{round(result['upload'] / 2 ** 20 / 8, 2)}</code> <b>мб/c</b>\n"
f"<b>Задержка:</b> <code>{round(result['ping'], 2)}</code> <b>мc</b>"
)
return await utils.answer(
message, text)