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

58 lines
2.0 KiB
Python
Raw Normal View History

2023-01-10 13:52:44 +02:00
from os import listdir
2023-02-17 17:46:33 +02:00
from classes.poster_client import PosterClient
2023-01-10 13:52:44 +02:00
from pyrogram.types import BotCommand, BotCommandScopeChat
from modules.utils import configGet, locale
2023-01-10 14:06:24 +02:00
2023-03-09 12:33:02 +02:00
async def register_commands(app: PosterClient) -> None:
2023-01-10 13:52:44 +02:00
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"):
2023-03-09 12:33:02 +02:00
commands_list.append(
BotCommand(
command,
locale(
command, "commands", locale=entry.replace(".json", "")
),
)
)
await app.set_bot_commands(
commands_list, language_code=entry.replace(".json", "")
)
2023-01-10 13:52:44 +02:00
# Registering user commands for fallback locale
commands_list = []
for command in configGet("commands"):
2023-03-09 12:33:02 +02:00
commands_list.append(
BotCommand(
command,
locale(command, "commands", locale=configGet("locale_fallback")),
)
)
2023-01-10 14:06:24 +02:00
await app.set_bot_commands(commands_list)
2023-01-10 13:52:44 +02:00
# Registering admin commands
commands_admin_list = []
2023-01-10 14:06:24 +02:00
2023-01-10 13:52:44 +02:00
if configGet("submit", "mode"):
for command in configGet("commands"):
2023-03-09 12:33:02 +02:00
commands_admin_list.append(
BotCommand(
command, locale(command, "commands", locale=configGet("locale"))
)
)
2023-01-10 13:52:44 +02:00
for command in configGet("commands_admin"):
2023-03-09 12:33:02 +02:00
commands_admin_list.append(
BotCommand(
command, locale(command, "commands_admin", locale=configGet("locale"))
)
)
2023-01-10 14:06:24 +02:00
2023-02-17 22:55:38 +02:00
for admin in app.admins:
2023-03-09 12:33:02 +02:00
await app.set_bot_commands(
commands_admin_list, scope=BotCommandScopeChat(chat_id=admin)
)