From a916cf0e33ed0e40eb32501508d3b0ca7d6bd87d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Jul 2024 04:28:51 +0200 Subject: [PATCH] Add `/help` command --- src/telegram/commands/help.rs | 21 +++++++++++++++++++++ src/telegram/commands/mod.rs | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/telegram/commands/help.rs diff --git a/src/telegram/commands/help.rs b/src/telegram/commands/help.rs new file mode 100644 index 00000000..95b6268d --- /dev/null +++ b/src/telegram/commands/help.rs @@ -0,0 +1,21 @@ +use anyhow::Context; +use teloxide::Bot; +use teloxide::payloads::SendMessageSetters; +use teloxide::requests::Requester; +use teloxide::types::{Message}; +use teloxide::utils::command::BotCommands; +use super::{CommandResult}; + +pub async fn handler(bot: Bot, message: Message) -> CommandResult { + let descriptions = super::Command::descriptions().to_string(); + + let text = format!("❓ Sono disponibili i seguenti comandi:\n\n{descriptions}"); + + let _reply = bot + .send_message(message.chat.id, text) + .reply_to_message_id(message.id) + .await + .context("Failed to send message")?; + + Ok(()) +} diff --git a/src/telegram/commands/mod.rs b/src/telegram/commands/mod.rs index 7ee35f8d..d9350a5d 100644 --- a/src/telegram/commands/mod.rs +++ b/src/telegram/commands/mod.rs @@ -13,12 +13,15 @@ use teloxide::utils::command::BotCommands; mod start; mod fortune; mod echo; +mod help; #[derive(Debug, Clone, BotCommands)] #[command(rename_rule = "lowercase")] -enum Command { +pub(self) enum Command { #[command(description = "Invia messaggio di introduzione.")] Start, + #[command(description = "Visualizza l'elenco dei comandi disponibili.")] + Help, #[command(description = "Mostra il tuo oroscopo di oggi.")] Fortune, #[command(description = "Ripeti il testo inviato.")] @@ -30,6 +33,7 @@ async fn handle_command(bot: Bot, command: Command, message: Message) -> Command match command { Command::Start => start::handler(bot, message).await, + Command::Help => help::handler(bot, message).await, Command::Fortune => fortune::handler(bot, message).await, Command::Echo(text) => echo::handler(bot, message, text).await, }