Skip to content

Commit

Permalink
Refactor code (pylint)
Browse files Browse the repository at this point in the history
  • Loading branch information
houshmand-2005 committed May 20, 2024
1 parent fc152b3 commit 2da1ed0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions telegram_bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions utils/get_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils/panel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion v2iplimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2da1ed0

Please sign in to comment.