summaryrefslogtreecommitdiff
path: root/src/callbacks.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-08-05 20:33:14 +0200
committerSanto Cariotti <santo@dcariotti.me>2021-08-05 20:33:14 +0200
commit5ddacf8e8131bacbcbd360b24c4c45b5380678ee (patch)
tree7ffb5aeb9adca95aaf344ae68d810c9456f01a4c /src/callbacks.rs
parent0ef059378e3b10c0eebcbb4e5abc0e033f06cd25 (diff)
feat: get spaces of a faculty
Diffstat (limited to 'src/callbacks.rs')
-rw-r--r--src/callbacks.rs48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/callbacks.rs b/src/callbacks.rs
index c670884..a82d5e9 100644
--- a/src/callbacks.rs
+++ b/src/callbacks.rs
@@ -1,18 +1,54 @@
use crate::browser;
+use crate::keyboard::make_inline_keyboard;
+use std::error::Error;
+use teloxide::{
+ payloads::EditMessageReplyMarkupSetters,
+ prelude::{AutoSend, Bot, CallbackQuery, Requester, UpdateWithCx},
+};
/// Handle the string of callback data
-pub async fn handler(text: &String) {
+pub async fn handler(
+ cx: &UpdateWithCx<AutoSend<Bot>, CallbackQuery>,
+ text: &String,
+) -> Result<bool, Box<dyn Error + Send + Sync>> {
let call: Vec<&str> = text.split("_").collect();
+ let chat_id = call[0];
// First part of `_` string is the type of callback we want to handle
- let type_ = call[0];
+ let type_ = call[1];
match type_ {
"faculty" => unsafe {
// Select the faculty
- let _ =
- browser::select_option("select2-results__option", "data-select2-id", call[1]).await;
+ match browser::select_option("select2-results__option", "data-select2-id", call[2])
+ .await
+ {
+ Ok(result) => {
+ if result {
+ let spaces = browser::get_spaces().await.unwrap();
+ let keyboard =
+ make_inline_keyboard(&spaces, "space", chat_id.parse::<i64>().unwrap())
+ .await;
+
+ // Edit the previous faculties message with spaces' buttons
+ cx.requester
+ .edit_message_reply_markup(
+ chat_id.to_string(),
+ cx.update.message.clone().unwrap().id,
+ )
+ .reply_markup(keyboard)
+ .await?;
+
+ return Ok(true);
+ } else {
+ return Ok(false);
+ }
+ }
+ Err(_) => {
+ return Ok(false);
+ }
+ }
},
- _ => {}
- };
+ _ => Ok(false),
+ }
}