From 376cff2226858a03a9215528dfe05af4a2288edf Mon Sep 17 00:00:00 2001 From: 5hojib Date: Thu, 2 Jan 2025 14:42:48 +0600 Subject: [PATCH] Speedtest --- bot/__main__.py | 1 + bot/core/handlers.py | 5 + bot/helper/telegram_helper/bot_commands.py | 1 + bot/modules/__init__.py | 172 +++++++++++---------- bot/modules/speedtest.py | 12 +- 5 files changed, 96 insertions(+), 95 deletions(-) diff --git a/bot/__main__.py b/bot/__main__.py index 9a0ed6e0e..ad12ef467 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -55,6 +55,7 @@ "StatsCommand": "- Check Bot & System stats", "CancelAllCommand": "- Cancel all tasks added by you to the bot", "HelpCommand": "- Get detailed help", + "SpeedTest": "- Get speedtest result", "BotSetCommand": "- [ADMIN] Open Bot settings", "LogCommand": "- [ADMIN] View log", "RestartCommand": "- [ADMIN] Restart the bot", diff --git a/bot/core/handlers.py b/bot/core/handlers.py index 90b8e9b45..9d82ad078 100644 --- a/bot/core/handlers.py +++ b/bot/core/handlers.py @@ -180,6 +180,11 @@ def add_handlers(): BotCommands.MediaInfoCommand, CustomFilters.authorized, ), + "speedtest": ( + speedtest, + BotCommands.SpeedTest, + CustomFilters.authorized, + ), } for handler_func, command_name, custom_filter in command_filters.values(): diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index fb65ca158..9e11cff71 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -36,6 +36,7 @@ def __init__(self): self.ClearLocalsCommand = f"clearlocals{i}" self.BotSetCommand = f"botsettings{i}" self.UserSetCommand = f"settings{i}" + self.SpeedTest = f"speedtest{i}" self.SelectCommand = f"sel{i}" self.RssCommand = f"rss{i}" diff --git a/bot/modules/__init__.py b/bot/modules/__init__.py index dd7ae5a4e..b35c5aa3d 100644 --- a/bot/modules/__init__.py +++ b/bot/modules/__init__.py @@ -1,85 +1,87 @@ -from .bot_settings import edit_bot_settings, send_bot_settings -from .cancel_task import cancel, cancel_all_buttons, cancel_all_update, cancel_multi -from .chat_permission import add_sudo, authorize, remove_sudo, unauthorize -from .clone import clone_node -from .exec import aioexecute, clear, execute -from .file_selector import confirm_selection, select -from .force_start import remove_from_queue -from .gd_count import count_node -from .gd_delete import delete_file -from .gd_search import gdrive_search, select_type -from .help import arg_usage, bot_help -from .mediainfo import mediainfo -from .mirror_leech import ( - leech, - mirror, -) -from .restart import ( - confirm_restart, - restart_bot, - restart_notification, - restart_sessions, -) -from .rss import get_rss_menu, rss_listener -from .search import initiate_search_tools, torrent_search, torrent_search_update -from .services import log, ping, start -from .shell import run_shell -from .stats import bot_stats, get_packages_version -from .status import status_pages, task_status -from .users_settings import ( - edit_user_settings, - get_users_settings, - send_user_settings, -) -from .ytdlp import ytdl, ytdl_leech - -__all__ = [ - "add_sudo", - "aioexecute", - "arg_usage", - "authorize", - "bot_help", - "bot_stats", - "cancel", - "cancel_all_buttons", - "cancel_all_update", - "cancel_multi", - "clear", - "clone_node", - "confirm_restart", - "confirm_selection", - "count_node", - "delete_file", - "edit_bot_settings", - "edit_user_settings", - "execute", - "gdrive_search", - "get_packages_version", - "get_rss_menu", - "get_users_settings", - "initiate_search_tools", - "leech", - "log", - "mediainfo", - "mirror", - "ping", - "remove_from_queue", - "remove_sudo", - "restart_bot", - "restart_notification", - "restart_sessions", - "rss_listener", - "run_shell", - "select", - "select_type", - "send_bot_settings", - "send_user_settings", - "start", - "status_pages", - "task_status", - "torrent_search", - "torrent_search_update", - "unauthorize", - "ytdl", - "ytdl_leech", -] +from .bot_settings import edit_bot_settings, send_bot_settings +from .cancel_task import cancel, cancel_all_buttons, cancel_all_update, cancel_multi +from .chat_permission import add_sudo, authorize, remove_sudo, unauthorize +from .clone import clone_node +from .exec import aioexecute, clear, execute +from .file_selector import confirm_selection, select +from .force_start import remove_from_queue +from .gd_count import count_node +from .gd_delete import delete_file +from .gd_search import gdrive_search, select_type +from .help import arg_usage, bot_help +from .mediainfo import mediainfo +from .mirror_leech import ( + leech, + mirror, +) +from .restart import ( + confirm_restart, + restart_bot, + restart_notification, + restart_sessions, +) +from .rss import get_rss_menu, rss_listener +from .search import initiate_search_tools, torrent_search, torrent_search_update +from .services import log, ping, start +from .shell import run_shell +from .speedtest import speedtest +from .stats import bot_stats, get_packages_version +from .status import status_pages, task_status +from .users_settings import ( + edit_user_settings, + get_users_settings, + send_user_settings, +) +from .ytdlp import ytdl, ytdl_leech + +__all__ = [ + "add_sudo", + "aioexecute", + "arg_usage", + "authorize", + "bot_help", + "bot_stats", + "cancel", + "cancel_all_buttons", + "cancel_all_update", + "cancel_multi", + "clear", + "clone_node", + "confirm_restart", + "confirm_selection", + "count_node", + "delete_file", + "edit_bot_settings", + "edit_user_settings", + "execute", + "gdrive_search", + "get_packages_version", + "get_rss_menu", + "get_users_settings", + "initiate_search_tools", + "leech", + "log", + "mediainfo", + "mirror", + "ping", + "remove_from_queue", + "remove_sudo", + "restart_bot", + "restart_notification", + "restart_sessions", + "rss_listener", + "run_shell", + "select", + "select_type", + "send_bot_settings", + "send_user_settings", + "speedtest", + "start", + "status_pages", + "task_status", + "torrent_search", + "torrent_search_update", + "unauthorize", + "ytdl", + "ytdl_leech", +] \ No newline at end of file diff --git a/bot/modules/speedtest.py b/bot/modules/speedtest.py index ed428d930..a7cef0a67 100644 --- a/bot/modules/speedtest.py +++ b/bot/modules/speedtest.py @@ -2,7 +2,7 @@ from pyrogram.handlers import MessageHandler from speedtest import Speedtest -from bot import LOGGER, bot +from bot import LOGGER from bot.helper.ext_utils.bot_utils import new_task from bot.helper.ext_utils.status_utils import get_readable_file_size from bot.helper.telegram_helper.bot_commands import BotCommands @@ -25,7 +25,7 @@ def get_speedtest_results(): test.upload() return test.results - result = await bot.loop.run_in_executor(None, get_speedtest_results) + result = get_speedtest_results if not result: await edit_message(speed, "Speedtest failed to complete.") @@ -43,11 +43,3 @@ def get_speedtest_results(): except Exception as e: LOGGER.error(str(e)) await edit_message(speed, string_speed) - - -bot.add_handler( - MessageHandler( - speedtest, - filters=command(BotCommands.SpeedCommand) & CustomFilters.authorized, - ), -)