mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-31 16:40:37 +01:00
Modify examples/simple_commands_bot
This commit is contained in:
parent
08ce1b4eed
commit
67a781fb20
2 changed files with 10 additions and 6 deletions
|
@ -9,5 +9,6 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
tokio = "0.2.9"
|
tokio = "0.2.9"
|
||||||
|
rand = "0.7.3"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
teloxide = { path = "../../" }
|
teloxide = { path = "../../" }
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use teloxide::{prelude::*, utils::command::BotCommand};
|
use teloxide::{prelude::*, utils::command::BotCommand};
|
||||||
|
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
#[derive(BotCommand)]
|
#[derive(BotCommand)]
|
||||||
#[command(rename = "lowercase", description = "These commands are supported:")]
|
#[command(rename = "lowercase", description = "These commands are supported:")]
|
||||||
enum Command {
|
enum Command {
|
||||||
|
@ -7,10 +9,8 @@ enum Command {
|
||||||
Help,
|
Help,
|
||||||
#[command(description = "be a cat.")]
|
#[command(description = "be a cat.")]
|
||||||
Meow,
|
Meow,
|
||||||
#[command(description = "be a dog.")]
|
#[command(description = "generate a random number within [0; 1).")]
|
||||||
Woof,
|
Generate,
|
||||||
#[command(description = "be a cow.")]
|
|
||||||
Moo,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_command(
|
async fn handle_command(
|
||||||
|
@ -34,9 +34,12 @@ async fn handle_command(
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
Command::Help => ctx.answer(Command::descriptions()).send().await?,
|
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::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(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue