2020-02-13 22:23:41 +01:00
|
|
|
use teloxide::{prelude::*, utils::command::BotCommand};
|
|
|
|
|
|
|
|
#[derive(BotCommand)]
|
|
|
|
#[command(rename = "lowercase", description = "These commands are supported:")]
|
|
|
|
enum Command {
|
|
|
|
#[command(description = "display this text.")]
|
|
|
|
Help,
|
2020-07-06 21:20:09 +02:00
|
|
|
#[command(description = "handle a username.")]
|
|
|
|
Username(String),
|
2020-07-26 19:47:02 +02:00
|
|
|
#[command(description = "handle a username and an age.", parse_with = "split")]
|
2020-07-06 21:20:09 +02:00
|
|
|
UsernameAndAge { username: String, age: u8 },
|
2020-02-18 23:54:41 +01:00
|
|
|
}
|
2020-02-13 22:23:41 +01:00
|
|
|
|
2020-07-26 19:47:02 +02:00
|
|
|
async fn answer(cx: UpdateWithCx<Message>, command: Command) -> ResponseResult<()> {
|
2020-02-13 22:23:41 +01:00
|
|
|
match command {
|
2020-02-18 23:54:41 +01:00
|
|
|
Command::Help => cx.answer(Command::descriptions()).send().await?,
|
2020-07-06 21:20:09 +02:00
|
|
|
Command::Username(username) => {
|
|
|
|
cx.answer_str(format!("Your username is @{}.", username)).await?
|
|
|
|
}
|
|
|
|
Command::UsernameAndAge { username, age } => {
|
2020-07-26 19:47:02 +02:00
|
|
|
cx.answer_str(format!("Your username is @{} and age is {}.", username, age)).await?
|
2020-07-06 21:20:09 +02:00
|
|
|
}
|
2020-02-13 22:23:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
run().await;
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run() {
|
|
|
|
teloxide::enable_logging!();
|
2020-07-25 15:45:57 +02:00
|
|
|
log::info!("Starting simple_commands_bot...");
|
2020-02-13 22:23:41 +01:00
|
|
|
|
|
|
|
let bot = Bot::from_env();
|
|
|
|
|
2020-08-02 06:11:09 +02:00
|
|
|
let bot_name: String = panic!("Your bot's name here");
|
|
|
|
teloxide::commands_repl(bot, bot_name, answer).await;
|
2020-02-13 22:23:41 +01:00
|
|
|
}
|