diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-07-29 20:02:47 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-07-29 20:02:47 +0200 |
commit | 89168ff11d4adb4ca51fe14e7d54fb2d69d392a8 (patch) | |
tree | 852241fc743b8f600bdf1c1787c1b7c283d2de27 /src/commands.rs | |
parent | a3be99079e9a644eaeaef857c52d7eebcc77e77e (diff) |
refactor: manage callbacks with tokio-stream
Diffstat (limited to 'src/commands.rs')
-rw-r--r-- | src/commands.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/commands.rs b/src/commands.rs index 1aee098..e498916 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,5 +1,7 @@ use std::error::Error; +use teloxide::payloads::SendMessageSetters; use teloxide::prelude::{AutoSend, Bot, Message, UpdateWithCx}; +use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup}; use teloxide::utils::command::BotCommand; #[derive(BotCommand)] @@ -7,14 +9,33 @@ use teloxide::utils::command::BotCommand; pub enum Command { #[command(description = "Display this text")] Help, + #[command(description = "Reserve a classroom for tomorrow", parse_with = "split")] + Room, } pub async fn handler( cx: UpdateWithCx<AutoSend<Bot>, Message>, - command: Command, ) -> Result<(), Box<dyn Error + Send + Sync>> { - match command { - Command::Help => cx.answer(Command::descriptions()).await?, - }; + let txt = cx.update.text(); + if txt.is_none() { + return Ok(()); + } + + if let Ok(command) = BotCommand::parse(txt.unwrap(), "unict-reservation") { + match command { + Command::Help => { + cx.answer(Command::descriptions()).await?; + } + Command::Room => { + let url_button = + InlineKeyboardButton::callback("hello".to_string(), "hello_call".to_string()); + let keyboard = InlineKeyboardMarkup::default().append_row(vec![url_button]); + cx.answer("Where?").reply_markup(keyboard).await?; + } + } + } else { + cx.reply_to("Command not found!").await?; + } + Ok(()) } |