# ---------------------------------------------------------------------------------
#░█▀▄░▄▀▀▄░█▀▄░█▀▀▄░█▀▀▄░█▀▀▀░▄▀▀▄░░░█▀▄▀█
#░█░░░█░░█░█░█░█▄▄▀░█▄▄█░█░▀▄░█░░█░░░█░▀░█
#░▀▀▀░░▀▀░░▀▀░░▀░▀▀░▀░░▀░▀▀▀▀░░▀▀░░░░▀░░▒▀
# Name: Speedtest
# Description: Module to run speedtest using speedtest library
# Author: @codrago_m
# ---------------------------------------------------------------------------------
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# ---------------------------------------------------------------------------------
# Author: @codrago
# Commands: speedtest
# scope: hikka_only
# meta developer: @codrago_m
# requires: speedtest-cli
# meta banner: https://raw.githubusercontent.com/coddrago/modules/refs/heads/main/banner.png
# meta pic: https://envs.sh/HoD.webp
# ---------------------------------------------------------------------------------
import speedtest
from .. import loader, utils
@loader.tds
class SpeedTestMod(loader.Module):
"""Module to run speedtest using speedtest library"""
strings = {
"name": "SpeedTest",
"running": "🌐 Running speedtest...",
"results": "🌐 Speedtest Results:\n\n"
"🌐 Download: {download} Mbps\n"
"📊 Upload: {upload} Mbps\n"
"✨ Ping: {ping} ms",
"error": "🚫 Error running speedtest: {error}",
}
strings_ru = {
"running": "🌐 Запуск теста скорости...",
"results": "🌐 Результаты теста скорости:\n\n"
"🌐 Скачивание: {download} Мбит/с\n"
"📊 Загрузка: {upload} Мбит/с\n"
"✨ Пинг: {ping} мс",
"error": "🚫 Ошибка при запуске теста скорости: {error}",
}
async def client_ready(self, client, db):
self.client = client
async def speedtestcmd(self, message):
"""Speedtest of your server internet"""
await utils.answer(message, self.strings("running"))
try:
st = speedtest.Speedtest()
st.download()
st.upload()
results = st.results.dict()
download = results["download"] / 1_000_000 # Convert to Mbps
upload = results["upload"] / 1_000_000 # Convert to Mbps
ping = results["ping"]
await utils.answer(
message,
self.strings("results").format(
ping=round(ping, 2),
download=round(download, 2),
upload=round(upload, 2)
)
)
except Exception as e:
await utils.answer(message, self.strings("error").format(error=str(e)))