2022-01-20 15:12:45 +00:00
|
|
|
|
# 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
|
2022-01-20 15:17:08 +00:00
|
|
|
|
from driver.veez import bot as app
|
2022-01-20 15:12:45 +00:00
|
|
|
|
from pyrogram import Client, filters
|
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(command(["speedtest", f"speedtest@{bname}"]) & ~filters.edited)
|
2022-01-25 07:44:23 +00:00
|
|
|
|
@sudo_users_only
|
|
|
|
|
async def run_speedtest(_, message: Message):
|
|
|
|
|
m = await message.reply_text("Running server speedtest -->")
|
2022-01-20 15:12:45 +00:00
|
|
|
|
try:
|
|
|
|
|
test = speedtest.Speedtest()
|
|
|
|
|
test.get_best_server()
|
2022-01-25 07:44:23 +00:00
|
|
|
|
m = await m.edit("Running download speedtest --->")
|
2022-01-20 15:12:45 +00:00
|
|
|
|
test.download()
|
2022-01-25 07:44:23 +00:00
|
|
|
|
m = await m.edit("Running upload speedtest ---->")
|
2022-01-20 15:12:45 +00:00
|
|
|
|
test.upload()
|
|
|
|
|
test.results.share()
|
|
|
|
|
result = test.results.dict()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return await m.edit(e)
|
2022-01-25 07:44:23 +00:00
|
|
|
|
m = await m.edit("🔄 Sharing speedtest results")
|
2022-01-20 15:12:45 +00:00
|
|
|
|
path = wget.download(result["share"])
|
|
|
|
|
|
|
|
|
|
output = f"""💡 **SpeedTest Results**
|
|
|
|
|
|
|
|
|
|
<u>**Client:**</u>
|
|
|
|
|
**ISP:** {result['client']['isp']}
|
|
|
|
|
**Country:** {result['client']['country']}
|
|
|
|
|
|
|
|
|
|
<u>**Server:**</u>
|
|
|
|
|
**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()
|