clessy-rs/src/main.rs

43 lines
1.0 KiB
Rust

use anyhow::Result;
use commands::{metafora, proverbio};
use teloxide::{prelude::*, utils::command::BotCommands};
mod commands;
#[tokio::main]
async fn main() -> Result<()> {
dotenvy::dotenv()?;
tracing_subscriber::fmt::init();
let bot = Bot::from_env();
Command::repl(bot, answer).await;
Ok(())
}
#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Comandi del bot:")]
enum Command {
#[command(description = "mostra questo testo")]
Help,
#[command(description = "genera metafora")]
Metafora,
#[command(description = "genera proverbio")]
Proverbio,
}
async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
match cmd {
Command::Help => {
bot.send_message(msg.chat.id, Command::descriptions().to_string())
.await?
}
Command::Metafora => bot.send_message(msg.chat.id, metafora::generate()).await?,
Command::Proverbio => bot.send_message(msg.chat.id, proverbio::generate()).await?,
};
Ok(())
}