From 2da1ed0946bfd9daa29794fddeee6324d6b10745 Mon Sep 17 00:00:00 2001 From: houshmand-2005 Date: Mon, 20 May 2024 20:01:34 +0330 Subject: [PATCH] Refactor code (pylint) --- core_test.py | 1 + telegram_bot/main.py | 8 ++++++++ utils/get_logs.py | 5 +++-- utils/panel_api.py | 2 +- v2iplimit.py | 7 ++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core_test.py b/core_test.py index 1d0a334..dfebdef 100644 --- a/core_test.py +++ b/core_test.py @@ -168,6 +168,7 @@ async def main(): # pylint: disable=too-many-statements await create_node_task(panel_data, tg, node) await asyncio.sleep(2) await asyncio.sleep(20) + # pylint: disable=duplicate-code print("Start 'check_and_add_new_nodes' Task Test: ") tg.create_task( check_and_add_new_nodes(panel_data, tg, nodes_list), diff --git a/telegram_bot/main.py b/telegram_bot/main.py index 36fab81..02973fd 100644 --- a/telegram_bot/main.py +++ b/telegram_bot/main.py @@ -391,6 +391,7 @@ async def show_special_limit_function( async def set_country_code(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """Set the country code for the bot.""" check = await check_admin_privilege(update) if check: return check @@ -428,6 +429,7 @@ async def send_backup(update: Update, _context: ContextTypes.DEFAULT_TYPE): async def set_except_users(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """Set the except users for the bot.""" check = await check_admin_privilege(update) if check: return check @@ -438,6 +440,7 @@ async def set_except_users(update: Update, _context: ContextTypes.DEFAULT_TYPE): async def set_except_users_handler(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """Write the except users to the config file.""" except_user = update.message.text.strip() await add_except_user(except_user) await update.message.reply_html( @@ -447,6 +450,7 @@ async def set_except_users_handler(update: Update, _context: ContextTypes.DEFAUL async def remove_except_user(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """remove the except users for the bot.""" check = await check_admin_privilege(update) if check: return check @@ -457,6 +461,7 @@ async def remove_except_user(update: Update, _context: ContextTypes.DEFAULT_TYPE async def remove_except_user_handler( update: Update, _context: ContextTypes.DEFAULT_TYPE ): + """remove the except users from the config file.""" except_user = await remove_except_user_from_config(update.message.text.strip()) if except_user: await update.message.reply_html( @@ -471,6 +476,7 @@ async def remove_except_user_handler( async def show_except_users(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """Show the except users for the bot.""" check = await check_admin_privilege(update) if check: return check @@ -484,6 +490,7 @@ async def show_except_users(update: Update, _context: ContextTypes.DEFAULT_TYPE) async def get_general_limit_number(update: Update, _context: ContextTypes.DEFAULT_TYPE): + """Get the general limit number for the bot.""" check = await check_admin_privilege(update) if check: return check @@ -494,6 +501,7 @@ async def get_general_limit_number(update: Update, _context: ContextTypes.DEFAUL async def get_general_limit_number_handler( update: Update, _context: ContextTypes.DEFAULT_TYPE ): + """Write the general limit number to the config file.""" try: limit_number = int(update.message.text.strip()) except ValueError: diff --git a/utils/get_logs.py b/utils/get_logs.py index 9876a10..7be9afc 100644 --- a/utils/get_logs.py +++ b/utils/get_logs.py @@ -17,7 +17,7 @@ ) sys.exit() from telegram_bot.send_message import send_logs -from utils.logs import logger +from utils.logs import logger # pylint: disable=ungrouped-imports from utils.panel_api import get_nodes, get_token from utils.parse_logs import parse_logs from utils.types import NodeType, PanelType @@ -44,7 +44,8 @@ async def get_panel_logs(panel_data: PanelType) -> None: while True: try: async with websockets.client.connect( - f"{scheme}://{panel_data.panel_domain}/api/core/logs?interval={INTERVAL}&token={token}" + f"{scheme}://{panel_data.panel_domain}/api/core" + + f"/logs?interval={INTERVAL}&token={token}" ) as ws: log_message = "Establishing connection for the main panel" await send_logs(log_message) diff --git a/utils/panel_api.py b/utils/panel_api.py index c465cf1..da1180c 100644 --- a/utils/panel_api.py +++ b/utils/panel_api.py @@ -143,7 +143,7 @@ async def enable_all_user(panel_data: PanelType) -> None | ValueError: if isinstance(users, ValueError): raise users for username in users: - for scheme in ["https", "http"]: # TODO:save what scheme is used + for scheme in ["https", "http"]: # add this later: save what scheme is used url = f"{scheme}://{panel_data.panel_domain}/api/user/{username.name}" status = {"status": "active"} try: diff --git a/v2iplimit.py b/v2iplimit.py index 654930b..cf9fb8e 100644 --- a/v2iplimit.py +++ b/v2iplimit.py @@ -96,4 +96,9 @@ async def main(): if __name__ == "__main__": - asyncio.run(main()) + while True: + try: + asyncio.run(main()) + except Exception as er: # pylint: disable=broad-except + logger.error(er) + asyncio.sleep(10)