mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-21 18:44:19 +00:00
Add /help
command
This commit is contained in:
parent
546b6a46a3
commit
a916cf0e33
2 changed files with 26 additions and 1 deletions
21
src/telegram/commands/help.rs
Normal file
21
src/telegram/commands/help.rs
Normal file
|
@ -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(())
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue