2022-12-17 01:58:33 +02:00
|
|
|
from os import listdir
|
2022-12-10 16:51:48 +02:00
|
|
|
from modules.logging import logWrite
|
2022-12-17 01:58:33 +02:00
|
|
|
from modules.utils import configGet, locale
|
2022-12-05 19:49:51 +02:00
|
|
|
from pyrogram.types import BotCommand, BotCommandScopeChat
|
|
|
|
from pyrogram.errors import bad_request_400
|
|
|
|
|
|
|
|
def commands_register(app):
|
|
|
|
|
2022-12-17 01:58:33 +02:00
|
|
|
valid_locales = []
|
|
|
|
files_locales = listdir(f'{configGet("locale", "locations")}')
|
|
|
|
for entry in files_locales:
|
|
|
|
valid_locales.append(".".join(entry.split(".")[:-1]))
|
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
# Registering user commands
|
|
|
|
commands_list = []
|
2022-12-17 01:58:33 +02:00
|
|
|
for command in locale("commands"):
|
|
|
|
commands_list.append(BotCommand(command, locale("commands")[command]))
|
2022-12-06 11:26:22 +02:00
|
|
|
app.set_bot_commands(commands_list)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-17 01:58:33 +02:00
|
|
|
# Registering user commands for each locale
|
|
|
|
for lc in valid_locales:
|
|
|
|
commands_list = []
|
|
|
|
for command in locale("commands", locale=lc):
|
|
|
|
commands_list.append(BotCommand(command, locale("commands",locale=lc)[command]))
|
|
|
|
app.set_bot_commands(commands_list, language_code=lc)
|
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
# Registering admin commands
|
|
|
|
commands_admin_list = []
|
2022-12-17 01:58:33 +02:00
|
|
|
for command in locale("commands"):
|
|
|
|
commands_admin_list.append(BotCommand(command, locale("commands")[command]))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-17 01:58:33 +02:00
|
|
|
for command in locale("commands_admin"):
|
|
|
|
commands_admin_list.append(BotCommand(command, locale("commands_admin")[command]))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
for admin in configGet("admins"):
|
|
|
|
try:
|
2022-12-06 11:26:22 +02:00
|
|
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=admin))
|
2022-12-05 19:49:51 +02:00
|
|
|
except bad_request_400.PeerIdInvalid:
|
|
|
|
pass
|
|
|
|
|
2022-12-10 16:51:48 +02:00
|
|
|
try:
|
|
|
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("owner")))
|
|
|
|
except bad_request_400.PeerIdInvalid:
|
|
|
|
logWrite(f"Could not register commands for bot owner. Perhaps user has not started the bot yet.")
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Registering admin group commands
|
|
|
|
commands_group_admin_list = []
|
2022-12-17 01:58:33 +02:00
|
|
|
for command in locale("commands_group_admin"):
|
|
|
|
commands_group_admin_list.append(BotCommand(command, locale("commands_group_admin")[command]))
|
2022-12-10 16:51:48 +02:00
|
|
|
try:
|
|
|
|
app.set_bot_commands(commands_group_admin_list, scope=BotCommandScopeChat(chat_id=configGet("admin_group")))
|
|
|
|
except bad_request_400.ChannelInvalid:
|
|
|
|
logWrite(f"Could not register commands for admin group. Bot is likely not in the group.")
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Registering destination group commands
|
|
|
|
commands_group_destination_list = []
|
2022-12-17 01:58:33 +02:00
|
|
|
for command in locale("commands_group_destination"):
|
|
|
|
commands_group_destination_list.append(BotCommand(command, locale("commands_group_destination")[command]))
|
2022-12-10 16:51:48 +02:00
|
|
|
try:
|
|
|
|
app.set_bot_commands(commands_group_destination_list, scope=BotCommandScopeChat(chat_id=configGet("destination_group")))
|
|
|
|
except bad_request_400.ChannelInvalid:
|
|
|
|
logWrite(f"Could not register commands for destination group. Bot is likely not in the group.")
|