From 82207aa430916156c99c4f77e6df8c34c94efc18 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Thu, 20 Jan 2022 22:12:45 +0700 Subject: [PATCH] added speedtest --- program/speedtest.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 program/speedtest.py diff --git a/program/speedtest.py b/program/speedtest.py new file mode 100644 index 0000000..6720013 --- /dev/null +++ b/program/speedtest.py @@ -0,0 +1,52 @@ +# credit to TeamYukki for this speedtest module + + +import os +import wget +import speedtest + +from program.utils.formatters import bytes +from driver.filters import command, other_filters +from driver.decorators import sudo_users_only +from config import BOT_USERNAME as bname +from driver.utils import bot as app +from pyrogram import Client, filters +from pyrogram.types import Message + + +@Client.on_message(command(["speedtest", f"speedtest@{bname}"]) & ~filters.edited) +@sudo_users_only +async def statsguwid(_, message: Message): + m = await message.reply_text("Running server speedtest.") + try: + test = speedtest.Speedtest() + test.get_best_server() + m = await m.edit("Running download speedtest..") + test.download() + m = await m.edit("Running upload speedtest...") + test.upload() + test.results.share() + result = test.results.dict() + except Exception as e: + return await m.edit(e) + m = await m.edit("Sharing speedtest results....") + path = wget.download(result["share"]) + + output = f"""💡 **SpeedTest Results** + +**Client:** +**ISP:** {result['client']['isp']} +**Country:** {result['client']['country']} + +**Server:** +**Name:** {result['server']['name']} +**Country:** {result['server']['country']}, {result['server']['cc']} +**Sponsor:** {result['server']['sponsor']} +**Latency:** {result['server']['latency']} + +⚡️ **Ping:** {result['ping']}""" + msg = await app.send_photo( + chat_id=message.chat.id, photo=path, caption=output + ) + os.remove(path) + await m.delete()