From b50f794d52c4a07202d010240d3e18184d22a8b0 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Sat, 8 Aug 2026 00:08:48 +0800 Subject: [PATCH] feat: register bot commands with Telegram Call setMyCommands at startup so clients show the command list in the / menu. handlers::register_commands wraps Command::bot_commands() (teloxide derives it from the #[command(description)] attributes); a registration failure only warns and does not stop the bot. --- crates/xmedia-bot/src/handlers.rs | 9 +++++++++ crates/xmedia-bot/src/main.rs | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/crates/xmedia-bot/src/handlers.rs b/crates/xmedia-bot/src/handlers.rs index aee380d..9765063 100644 --- a/crates/xmedia-bot/src/handlers.rs +++ b/crates/xmedia-bot/src/handlers.rs @@ -393,6 +393,15 @@ fn plural(n: usize) -> &'static str { if n == 1 { "y" } else { "ies" } } +/// Registers the bot's command list with Telegram so clients show it in the +/// `/` menu (Bot API `setMyCommands`). +pub async fn register_commands(bot: &Bot) -> Result<(), RequestError> { + let commands = Command::bot_commands(); + bot.set_my_commands(commands.clone()).await?; + log::info!("registered {} commands", commands.len()); + Ok(()) +} + /// For locally produced media (encoded ugoira MP4) the thumbnail URL is a /// hotlink-protected remote URL Telegram may not fetch; let Telegram generate /// its own thumbnail instead. diff --git a/crates/xmedia-bot/src/main.rs b/crates/xmedia-bot/src/main.rs index 95ad9fa..39c0de5 100644 --- a/crates/xmedia-bot/src/main.rs +++ b/crates/xmedia-bot/src/main.rs @@ -44,6 +44,11 @@ async fn main() { let bot = Bot::from_env(); + // Register the command list with Telegram (client `/` menu). + if let Err(e) = handlers::register_commands(&bot).await { + log::warn!("failed to register commands: {e}"); + } + log::info!( "config: {} admin(s), edit-message TTL {}s", CONFIG.admin_ids.len(),