From da3dd3a2fe60b088ce88d6b81102c8c12740e7ce Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 9 Jan 2023 12:39:39 +0100 Subject: [PATCH] Changed debug logging logic --- modules/commands/reapply.py | 23 +++++++++++++++-------- modules/commands/resetcommands.py | 23 ++++++++--------------- modules/inline.py | 6 ++---- modules/scheduled.py | 11 ++++------- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/modules/commands/reapply.py b/modules/commands/reapply.py index c817c77..aec1829 100644 --- a/modules/commands/reapply.py +++ b/modules/commands/reapply.py @@ -34,14 +34,21 @@ async def cmd_reapply(app: Client, msg: Message): await welcome_pass(app, msg, once_again=True) else: - await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([ - [ - InlineKeyboardButton(locale("reapply_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}") - ], - [ - InlineKeyboardButton(locale("reapply_new_one", "button", locale=holo_user), f"reapply_new_{msg.id}") - ] - ])) + + if holo_user.sponsorship_state()[1] is True: + + await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([ + [ + InlineKeyboardButton(locale("reapply_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}") + ], + [ + InlineKeyboardButton(locale("reapply_new_one", "button", locale=holo_user), f"reapply_new_{msg.id}") + ] + ])) + + else: + holo_user.application_restart(reapply=True) + await welcome_pass(app, msg, once_again=True) else: diff --git a/modules/commands/resetcommands.py b/modules/commands/resetcommands.py index 5f5ef15..e9f2c5a 100644 --- a/modules/commands/resetcommands.py +++ b/modules/commands/resetcommands.py @@ -24,42 +24,35 @@ async def cmd_resetcommands(app: Client, msg: Message): if entry.endswith(".json"): valid_locales.append(".".join(entry.split(".")[:-1])) - if configGet("debug") is True: - logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}') + logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}', debug=True) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups"))) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups"))) for admin in configGet("admins"): try: - if configGet("debug") is True: - logWrite(f'Resetting commands for admin {admin}') + logWrite(f'Resetting commands for admin {admin}', debug=True) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin)) except bad_request_400.PeerIdInvalid: pass try: - if configGet("debug") is True: - logWrite(f'Resetting commands for owner {configGet("owner")}') + logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True) for lc in valid_locales: - if configGet("debug") is True: - logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]') + logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")), language_code=lc) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner"))) except bad_request_400.PeerIdInvalid: pass for lc in valid_locales: - if configGet("debug") is True: - logWrite(f'Resetting commands for locale {lc}') + logWrite(f'Resetting commands for locale {lc}', debug=True) await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc) - if configGet("debug") is True: - logWrite(f'Resetting default commands') + logWrite(f'Resetting default commands', debug=True) await app.delete_bot_commands() await msg.reply_text("OK", quote=should_quote(msg)) - if configGet("debug") is True: - logWrite(str(await app.get_bot_commands())) - logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner"))))) + logWrite(str(await app.get_bot_commands()), debug=True) + logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))), debug=True) # ============================================================================================================================== \ No newline at end of file diff --git a/modules/inline.py b/modules/inline.py index a5c9d28..ce25f7b 100644 --- a/modules/inline.py +++ b/modules/inline.py @@ -78,8 +78,7 @@ async def inline_answer(client: Client, inline_query: InlineQuery): try: holo_user = HoloUser(inline_query.from_user) except (UserNotFoundError, UserInvalidError): - if configGet("debug") is True: - logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query") + logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query", debug=True) await inline_query.answer( results=results_forbidden ) @@ -87,8 +86,7 @@ async def inline_answer(client: Client, inline_query: InlineQuery): if path.exists(path.join(configGet("cache", "locations"), "group_members")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "group_members"))): if path.exists(path.join(configGet("cache", "locations"), "admins")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "admins"))): - if configGet("debug") is True: - logWrite(f"{inline_query.from_user.id} is not an admin and not in members group, ignoring inline query") + logWrite(f"{inline_query.from_user.id} is not an admin and not in members group, ignoring inline query", debug=True) await inline_query.answer( results=results_forbidden ) diff --git a/modules/scheduled.py b/modules/scheduled.py index a9b199f..bd0d0d0 100644 --- a/modules/scheduled.py +++ b/modules/scheduled.py @@ -24,8 +24,7 @@ if configGet("enabled", "scheduler", "cache_members"): list_of_users.append(member.user.id) makedirs(configGet("cache", "locations"), exist_ok=True) jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members")) - if configGet("debug") is True: - logWrite("User group caching performed") + logWrite("User group caching performed", debug=True) if configGet("enabled", "scheduler", "cache_admins"): @scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_admins")) @@ -35,8 +34,7 @@ if configGet("enabled", "scheduler", "cache_admins"): list_of_users.append(member.user.id) makedirs(configGet("cache", "locations"), exist_ok=True) jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins")) - if configGet("debug") is True: - logWrite("Admin group caching performed") + logWrite("Admin group caching performed", debug=True) # Cache the avatars of group members if configGet("enabled", "scheduler", "cache_avatars"): @@ -159,8 +157,7 @@ async def commands_register(): enabled = True if enabled is False: - if configGet("debug") is True: - logWrite(f"Not registering {command} at all") + logWrite(f"Not registering {command} at all", debug=True) continue for permission in config_commands[command]["permissions"]: @@ -223,4 +220,4 @@ async def commands_register(): if configGet("debug") is True: print(commands, flush=True) - logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}") \ No newline at end of file + logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}", debug=True) \ No newline at end of file