This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramPoster/modules/commands_register.py
2023-01-10 13:06:24 +01:00

33 lines
1.5 KiB
Python

from os import listdir
from pyrogram.client import Client
from pyrogram.types import BotCommand, BotCommandScopeChat
from modules.utils import configGet, locale
async def register_commands(app: Client):
if configGet("submit", "mode"):
# Registering user commands
for entry in listdir(configGet("locale", "locations")):
if entry.endswith(".json"):
commands_list = []
for command in configGet("commands"):
commands_list.append(BotCommand(command, locale(command, "commands", locale=entry.replace(".json", ""))))
await app.set_bot_commands(commands_list, language_code=entry.replace(".json", ""))
# Registering user commands for fallback locale
commands_list = []
for command in configGet("commands"):
commands_list.append(BotCommand(command, locale(command, "commands", locale=configGet("locale_fallback"))))
await app.set_bot_commands(commands_list)
# Registering admin commands
commands_admin_list = []
if configGet("submit", "mode"):
for command in configGet("commands"):
commands_admin_list.append(BotCommand(command, locale(command, "commands", locale=configGet("locale"))))
for command in configGet("commands_admin"):
commands_admin_list.append(BotCommand(command, locale(command, "commands_admin", locale=configGet("locale"))))
await app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("admin")))