summaryrefslogtreecommitdiff
path: root/src/commands.rs
blob: e4989164477affe064af75d5ea9d17eb23ca989b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)]
#[command(rename = "lowercase", description = "These commands are supported:")]
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>,
) -> Result<(), Box<dyn Error + Send + Sync>> {
    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(())
}