From 185235a336f7f6c0324ce763958e92008757e562 Mon Sep 17 00:00:00 2001 From: profitroll Date: Tue, 16 May 2023 20:53:59 +0200 Subject: [PATCH] Moved command registration to the events on start --- modules/app.py | 45 +++++++++++++++++++++++++++ plugins/register_commands.py | 60 ------------------------------------ 2 files changed, 45 insertions(+), 60 deletions(-) delete mode 100644 plugins/register_commands.py diff --git a/modules/app.py b/modules/app.py index 757e61b..b9ac8da 100644 --- a/modules/app.py +++ b/modules/app.py @@ -7,6 +7,7 @@ from libbot import config_get from pyrogram.client import Client from pyrogram.errors import BadRequest from pyrogram.raw.all import layer +from pyrogram.types import BotCommand, BotCommandScopeChat from ujson import loads logger = logging.getLogger(__name__) @@ -47,6 +48,50 @@ class PyroClient(Client): except BadRequest: logger.warning("Unable to send message to report chat.") + await self.set_bot_commands( + [ + BotCommand("help", "Меню допомоги"), + BotCommand("balance", "Баланс картки"), + BotCommand("topup", "Поповнити картку"), + BotCommand("setcard", "Прив'язати картку"), + BotCommand("resetcard", "Відв'язати картку"), + ], + language_code="uk", + ) + + await self.set_bot_commands( + [ + BotCommand("help", "Меню допомоги"), + BotCommand("balance", "Баланс картки"), + BotCommand("topup", "Поповнити картку"), + BotCommand("setcard", "Прив'язати картку"), + BotCommand("resetcard", "Відв'язати картку"), + ], + language_code="ru", + ) + + await self.set_bot_commands( + [ + BotCommand("help", "Help menu"), + BotCommand("balance", "Card's balance"), + BotCommand("topup", "Refill card"), + BotCommand("setcard", "Link card"), + BotCommand("resetcard", "Unlink card"), + ] + ) + + await self.set_bot_commands( + [ + BotCommand("help", "Help menu"), + BotCommand("balance", "Card's balance"), + BotCommand("topup", "Refill card"), + BotCommand("setcard", "Link card"), + BotCommand("resetcard", "Unlink card"), + BotCommand("shutdown", "Turn off the bot"), + ], + scope=BotCommandScopeChat(chat_id=await config_get("owner_id")), + ) + async def stop(self): try: await self.send_message( diff --git a/plugins/register_commands.py b/plugins/register_commands.py deleted file mode 100644 index 05a384f..0000000 --- a/plugins/register_commands.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- - -import logging - -from libbot import config_get -from pyrogram import filters -from pyrogram.client import Client -from pyrogram.types import BotCommand, BotCommandScopeChat, Message - -logger = logging.getLogger(__name__) - - -@Client.on_message( - ~filters.scheduled & filters.command(["register_commands"], prefixes="/") # type: ignore -) -async def command_register_commands(app: Client, msg: Message): - if msg.from_user.id == await config_get("owner_id"): - app.set_bot_commands( - [ - BotCommand("help", "Меню допомоги"), - BotCommand("balance", "Баланс картки"), - BotCommand("topup", "Поповнити картку"), - BotCommand("setcard", "Прив'язати картку"), - BotCommand("resetcard", "Відв'язати картку"), - ], - language_code="uk", - ) # type: ignore - - app.set_bot_commands( - [ - BotCommand("help", "Меню допомоги"), - BotCommand("balance", "Баланс картки"), - BotCommand("topup", "Поповнити картку"), - BotCommand("setcard", "Прив'язати картку"), - BotCommand("resetcard", "Відв'язати картку"), - ], - language_code="ru", - ) # type: ignore - - app.set_bot_commands( - [ - BotCommand("help", "Help menu"), - BotCommand("balance", "Card's balance"), - BotCommand("topup", "Refill card"), - BotCommand("setcard", "Link card"), - BotCommand("resetcard", "Unlink card"), - ] - ) # type: ignore - - app.set_bot_commands( - [ - BotCommand("help", "Help menu"), - BotCommand("balance", "Card's balance"), - BotCommand("topup", "Refill card"), - BotCommand("setcard", "Link card"), - BotCommand("resetcard", "Unlink card"), - BotCommand("shutdown", "Turn off the bot"), - ], - scope=BotCommandScopeChat(chat_id=await config_get("owner_id")), - ) # type: ignore