summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-08-23 14:57:59 +0200
committerSanto Cariotti <santo@dcariotti.me>2021-08-23 14:57:59 +0200
commitc14904124c0d3bc13b8f0739eb174ee5aa7c8b50 (patch)
treee0ddf726e656d6f030a344321bc29a602d4ee6b5 /src
parent9b229737e671fba989191409e927e677a4c960f7 (diff)
feat: reserve a study hour
Diffstat (limited to 'src')
-rw-r--r--src/browser/mod.rs10
-rw-r--r--src/browser/web_browser.rs21
-rw-r--r--src/callbacks.rs28
3 files changed, 59 insertions, 0 deletions
diff --git a/src/browser/mod.rs b/src/browser/mod.rs
index 4c7ef8e..528849d 100644
--- a/src/browser/mod.rs
+++ b/src/browser/mod.rs
@@ -72,3 +72,13 @@ pub async unsafe fn get_timetable() -> WebDriverResult<Option<HashMap<String, St
Ok(None)
}
+
+pub async unsafe fn select_table_row(index: &str) -> WebDriverResult<bool> {
+ if let Some(driver) = &WEB_BROWSER {
+ let result = driver.select_timetable_row(index).await?;
+
+ return Ok(result);
+ }
+
+ Ok(false)
+}
diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs
index 5a855d5..10dacb7 100644
--- a/src/browser/web_browser.rs
+++ b/src/browser/web_browser.rs
@@ -188,6 +188,27 @@ impl Browser {
Ok(None)
}
+
+ // Select the row for the timetable booking
+ pub async unsafe fn select_timetable_row(&self, index: &str) -> WebDriverResult<bool> {
+ if let Some(_d) = &self.driver {
+ _d.find_element(By::Css(
+ &format!("#slotContainerTable tr:nth-child({}) td", index).to_owned()[..],
+ ))
+ .await?
+ .click()
+ .await?;
+ thread::sleep(time::Duration::from_millis(2000));
+ _d.find_element(By::Css("#partialQuestionYesNoConfirmButton:last-child"))
+ .await?
+ .click()
+ .await?;
+
+ return Ok(true);
+ }
+
+ Ok(false)
+ }
}
/// The static unsafe variable used to open a web browser
diff --git a/src/callbacks.rs b/src/callbacks.rs
index 53ae07c..8b4e846 100644
--- a/src/callbacks.rs
+++ b/src/callbacks.rs
@@ -91,6 +91,34 @@ pub async fn handler(
}
}
},
+ "timetable" => unsafe {
+ match browser::select_table_row(call[2]).await {
+ Ok(result) => {
+ if result {
+ cx.requester
+ .edit_message_text(
+ chat_id.to_string(),
+ cx.update.message.clone().unwrap().id,
+ "Reservation made! ✅",
+ )
+ .await?;
+ return Ok(true);
+ } else {
+ cx.requester
+ .edit_message_text(
+ chat_id.to_string(),
+ cx.update.message.clone().unwrap().id,
+ "Error, try again! ⚠️",
+ )
+ .await?;
+ return Ok(false);
+ }
+ }
+ Err(_) => {
+ return Ok(false);
+ }
+ }
+ },
_ => Ok(false),
}
}