1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-25 04:24:20 +00:00

Add /help command

This commit is contained in:
Steffo 2024-07-08 04:28:51 +02:00
parent 546b6a46a3
commit a916cf0e33
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 26 additions and 1 deletions

View 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(())
}

View file

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