Modify examples/simple_commands_bot

This commit is contained in:
Temirkhan Myrzamadi 2020-02-14 04:35:36 +06:00
parent 08ce1b4eed
commit 67a781fb20
2 changed files with 10 additions and 6 deletions

View file

@ -9,5 +9,6 @@ edition = "2018"
[dependencies]
log = "0.4.8"
tokio = "0.2.9"
rand = "0.7.3"
pretty_env_logger = "0.4.0"
teloxide = { path = "../../" }

View file

@ -1,5 +1,7 @@
use teloxide::{prelude::*, utils::command::BotCommand};
use rand::{thread_rng, Rng};
#[derive(BotCommand)]
#[command(rename = "lowercase", description = "These commands are supported:")]
enum Command {
@ -7,10 +9,8 @@ enum Command {
Help,
#[command(description = "be a cat.")]
Meow,
#[command(description = "be a dog.")]
Woof,
#[command(description = "be a cow.")]
Moo,
#[command(description = "generate a random number within [0; 1).")]
Generate,
}
async fn handle_command(
@ -34,9 +34,12 @@ async fn handle_command(
match command {
Command::Help => ctx.answer(Command::descriptions()).send().await?,
Command::Generate => {
ctx.answer(thread_rng().gen_range(0.0, 1.0).to_string())
.send()
.await?
}
Command::Meow => ctx.answer("I am a cat! Meow!").send().await?,
Command::Woof => ctx.answer("I am a dog! Woof!").send().await?,
Command::Moo => ctx.answer("I am a cow! Moo!").send().await?,
};
Ok(())