Check for deleted items

This commit is contained in:
SkyfallWasTaken 2024-07-03 17:46:06 +01:00
parent 142a7fbb52
commit d993eb695a
2 changed files with 18 additions and 0 deletions

View file

@ -58,6 +58,17 @@ pub fn format_new_item(item: &ShopItem) -> String {
} }
} }
pub fn format_deleted_item(item: &ShopItem) -> String {
formatdoc! {
"*Item DELETED:* {full_name}
*Description:* {description}
*Price:* {price}",
full_name = item.full_name,
description = item.description.as_ref().unwrap_or(&"_not set_".into()),
price = item.price,
}
}
#[cfg(test)] #[cfg(test)]
mod format_new_tests { mod format_new_tests {
use super::*; use super::*;

View file

@ -58,6 +58,13 @@ async fn run_scrape(env: Env) -> Result<String> {
} }
} }
// Check if any items have been removed.
for item in &old_items {
if !available_items.iter().any(|i| i.id == item.id) {
result.push(format::format_deleted_item(item));
}
}
// If there are any updates/new items, send a message to the Slack webhook. // If there are any updates/new items, send a message to the Slack webhook.
if result.is_empty() { if result.is_empty() {
return Ok("No changes detected".into()); return Ok("No changes detected".into());