summaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 7ee8d83..512e3c1 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -1,9 +1,9 @@
use crate::browser;
use crate::config::Config;
+use crate::keyboard::make_inline_keyboard;
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)]
@@ -50,35 +50,11 @@ pub async fn handler(
Command::Room => {
let faculties;
- // This is an array of array because the `InlineKeyboardMarkup`
- // considers each array as a row.
- // So, using this format Vec<Vec<..>> will print a button
- // in `n` different rows in only 1 column.
- let mut faculties_array: Vec<Vec<InlineKeyboardButton>> = vec![];
unsafe {
faculties = browser::get_faculties().await.unwrap();
}
- if let Some(faculties_texts) = faculties {
- for (key, value) in faculties_texts {
- faculties_array.push(vec![InlineKeyboardButton::callback(
- value,
- format!("faculty_{}", key),
- )]);
- }
- } else {
- // If the response of the Option `faculties` is None, just answer
- // an useless button with a text.
- // I still don't know if it's a good idea to use a callback instead of
- // a normal text button, but I could handle any such kind of callback
- faculties_array.push(vec![InlineKeyboardButton::callback(
- "No such element".to_string(),
- "".into(),
- )]);
- }
-
- // The `new` method accepts an interator
- let keyboard = InlineKeyboardMarkup::new(faculties_array);
+ let keyboard = make_inline_keyboard(&faculties, "faculty").await;
cx.answer("Where?").reply_markup(keyboard).await?;
}
}