Register Telegram command menu
This commit is contained in:
@@ -54,14 +54,17 @@ The database will be saved in `./bot_db/media.db`.
|
|||||||
|
|
||||||
**Searching inline** — in any chat type `@yourbotusername keyword` to search and send.
|
**Searching inline** — in any chat type `@yourbotusername keyword` to search and send.
|
||||||
|
|
||||||
|
Telegram suggests these commands as you type `/`, with a short description beside each suggestion.
|
||||||
|
|
||||||
**Commands**
|
**Commands**
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
| `/start` | Start the bot and show usage instructions |
|
||||||
| `/menu` | Show the available commands |
|
| `/menu` | Show the available commands |
|
||||||
| `/list` | Show all saved media |
|
| `/list` | Show all saved media |
|
||||||
| `/edit [search]` | Select a meme and edit its keywords (admin only) |
|
| `/edit [search]` | Select a meme and edit its keywords (admin only) |
|
||||||
| `/delete <id>` | Remove an entry (get ID from `/list`) |
|
| `/delete <id>` | Remove an entry (get ID from `/list`; admin only) |
|
||||||
| `/cancel` | Cancel current add operation |
|
| `/cancel` | Cancel current add operation |
|
||||||
|
|
||||||
### Moving to another server
|
### Moving to another server
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ from aiogram.fsm.context import FSMContext
|
|||||||
from aiogram.fsm.state import State, StatesGroup
|
from aiogram.fsm.state import State, StatesGroup
|
||||||
from aiogram.fsm.storage.memory import MemoryStorage
|
from aiogram.fsm.storage.memory import MemoryStorage
|
||||||
from aiogram.types import (
|
from aiogram.types import (
|
||||||
|
BotCommand,
|
||||||
|
BotCommandScopeChat,
|
||||||
CallbackQuery,
|
CallbackQuery,
|
||||||
InlineKeyboardButton,
|
InlineKeyboardButton,
|
||||||
InlineKeyboardMarkup,
|
InlineKeyboardMarkup,
|
||||||
@@ -40,6 +42,18 @@ ADMIN_USERS: set[int] = {
|
|||||||
bot = Bot(token=BOT_TOKEN)
|
bot = Bot(token=BOT_TOKEN)
|
||||||
dp = Dispatcher(storage=MemoryStorage())
|
dp = Dispatcher(storage=MemoryStorage())
|
||||||
|
|
||||||
|
USER_COMMANDS = [
|
||||||
|
BotCommand(command="start", description="Start the bot"),
|
||||||
|
BotCommand(command="menu", description="Show available commands"),
|
||||||
|
BotCommand(command="list", description="Browse saved memes"),
|
||||||
|
BotCommand(command="cancel", description="Cancel current operation"),
|
||||||
|
]
|
||||||
|
ADMIN_COMMANDS = [
|
||||||
|
*USER_COMMANDS,
|
||||||
|
BotCommand(command="edit", description="Edit meme keywords"),
|
||||||
|
BotCommand(command="delete", description="Remove a meme by ID"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def is_allowed(user_id: int) -> bool:
|
def is_allowed(user_id: int) -> bool:
|
||||||
if user_id in ADMIN_USERS:
|
if user_id in ADMIN_USERS:
|
||||||
@@ -54,6 +68,20 @@ def is_admin(user_id: int) -> bool:
|
|||||||
return not ALLOWED_USERS or user_id in ALLOWED_USERS
|
return not ALLOWED_USERS or user_id in ALLOWED_USERS
|
||||||
|
|
||||||
|
|
||||||
|
async def register_commands() -> None:
|
||||||
|
"""Publish Telegram's command menu with role-appropriate suggestions."""
|
||||||
|
if not ADMIN_USERS:
|
||||||
|
await bot.set_my_commands(ADMIN_COMMANDS)
|
||||||
|
return
|
||||||
|
|
||||||
|
await bot.set_my_commands(USER_COMMANDS)
|
||||||
|
for admin_id in ADMIN_USERS:
|
||||||
|
await bot.set_my_commands(
|
||||||
|
ADMIN_COMMANDS,
|
||||||
|
scope=BotCommandScopeChat(chat_id=admin_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AddMedia(StatesGroup):
|
class AddMedia(StatesGroup):
|
||||||
waiting_for_keywords = State()
|
waiting_for_keywords = State()
|
||||||
|
|
||||||
@@ -374,6 +402,7 @@ async def inline_handler(query: InlineQuery):
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
await db.init_db()
|
await db.init_db()
|
||||||
|
await register_commands()
|
||||||
log.info("Bot starting…")
|
log.info("Bot starting…")
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user