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, }