Bug fixes and improvements #8

Merged
profitroll merged 23 commits from dev into master 2023-01-11 17:22:34 +02:00
4 changed files with 29 additions and 34 deletions
Showing only changes of commit da3dd3a2fe - Show all commits

View File

@ -34,6 +34,9 @@ async def cmd_reapply(app: Client, msg: Message):
await welcome_pass(app, msg, once_again=True) await welcome_pass(app, msg, once_again=True)
else: else:
if holo_user.sponsorship_state()[1] is True:
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([ 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_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}")
@ -43,6 +46,10 @@ async def cmd_reapply(app: Client, msg: Message):
] ]
])) ]))
else:
holo_user.application_restart(reapply=True)
await welcome_pass(app, msg, once_again=True)
else: else:
await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([ await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([

View File

@ -24,42 +24,35 @@ async def cmd_resetcommands(app: Client, msg: Message):
if entry.endswith(".json"): if entry.endswith(".json"):
valid_locales.append(".".join(entry.split(".")[:-1])) 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")}', debug=True)
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}')
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups"))) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups"))) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
for admin in configGet("admins"): for admin in configGet("admins"):
try: try:
if configGet("debug") is True: logWrite(f'Resetting commands for admin {admin}', debug=True)
logWrite(f'Resetting commands for admin {admin}')
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin)) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
except bad_request_400.PeerIdInvalid: except bad_request_400.PeerIdInvalid:
pass pass
try: try:
if configGet("debug") is True: logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True)
logWrite(f'Resetting commands for owner {configGet("owner")}')
for lc in valid_locales: for lc in valid_locales:
if configGet("debug") is True: logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True)
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]')
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")), language_code=lc)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner"))) await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))
except bad_request_400.PeerIdInvalid: except bad_request_400.PeerIdInvalid:
pass pass
for lc in valid_locales: for lc in valid_locales:
if configGet("debug") is True: logWrite(f'Resetting commands for locale {lc}', debug=True)
logWrite(f'Resetting commands for locale {lc}')
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc) await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
if configGet("debug") is True: logWrite(f'Resetting default commands', debug=True)
logWrite(f'Resetting default commands')
await app.delete_bot_commands() await app.delete_bot_commands()
await msg.reply_text("OK", quote=should_quote(msg)) await msg.reply_text("OK", quote=should_quote(msg))
if configGet("debug") is True: logWrite(str(await app.get_bot_commands()), debug=True)
logWrite(str(await app.get_bot_commands())) logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))), debug=True)
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))))
# ============================================================================================================================== # ==============================================================================================================================

View File

@ -78,8 +78,7 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
try: try:
holo_user = HoloUser(inline_query.from_user) holo_user = HoloUser(inline_query.from_user)
except (UserNotFoundError, UserInvalidError): except (UserNotFoundError, UserInvalidError):
if configGet("debug") is True: logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query", debug=True)
logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query")
await inline_query.answer( await inline_query.answer(
results=results_forbidden 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"), "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 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", debug=True)
logWrite(f"{inline_query.from_user.id} is not an admin and not in members group, ignoring inline query")
await inline_query.answer( await inline_query.answer(
results=results_forbidden results=results_forbidden
) )

View File

@ -24,8 +24,7 @@ if configGet("enabled", "scheduler", "cache_members"):
list_of_users.append(member.user.id) list_of_users.append(member.user.id)
makedirs(configGet("cache", "locations"), exist_ok=True) makedirs(configGet("cache", "locations"), exist_ok=True)
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members")) jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members"))
if configGet("debug") is True: logWrite("User group caching performed", debug=True)
logWrite("User group caching performed")
if configGet("enabled", "scheduler", "cache_admins"): if configGet("enabled", "scheduler", "cache_admins"):
@scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "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) list_of_users.append(member.user.id)
makedirs(configGet("cache", "locations"), exist_ok=True) makedirs(configGet("cache", "locations"), exist_ok=True)
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins")) jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins"))
if configGet("debug") is True: logWrite("Admin group caching performed", debug=True)
logWrite("Admin group caching performed")
# Cache the avatars of group members # Cache the avatars of group members
if configGet("enabled", "scheduler", "cache_avatars"): if configGet("enabled", "scheduler", "cache_avatars"):
@ -159,8 +157,7 @@ async def commands_register():
enabled = True enabled = True
if enabled is False: if enabled is False:
if configGet("debug") is True: logWrite(f"Not registering {command} at all", debug=True)
logWrite(f"Not registering {command} at all")
continue continue
for permission in config_commands[command]["permissions"]: for permission in config_commands[command]["permissions"]:
@ -223,4 +220,4 @@ async def commands_register():
if configGet("debug") is True: if configGet("debug") is True:
print(commands, flush=True) print(commands, flush=True)
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}") logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}", debug=True)