From eaafe83dae4c12d44c9c7672a3b02c04b110cf6b Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 5 Aug 2021 19:16:49 +0200 Subject: feat: create a module to manage the keyboard response --- src/commands.rs | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'src/commands.rs') 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> will print a button - // in `n` different rows in only 1 column. - let mut faculties_array: Vec> = 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?; } } -- cgit v1.2.3-18-g5258