Moved command registration to the events on start

This commit is contained in:
Profitroll 2023-05-16 20:53:59 +02:00
parent ccb9e79cd7
commit 185235a336
2 changed files with 45 additions and 60 deletions

View File

@ -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(

View File

@ -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