Add IncidentColorMap enum
All checks were successful
Build and push container image / build (push) Successful in 12m31s
Build and push container image / deploy (push) Successful in 36s

This commit is contained in:
toast 2024-08-15 16:16:23 +10:00
parent 1fa75a4d6f
commit dfa1ae75b2
5 changed files with 41 additions and 16 deletions

2
Cargo.lock generated
View File

@ -1023,7 +1023,7 @@ dependencies = [
[[package]] [[package]]
name = "kon" name = "kon"
version = "0.3.16" version = "0.3.17"
dependencies = [ dependencies = [
"bb8", "bb8",
"bb8-postgres", "bb8-postgres",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "kon" name = "kon"
version = "0.3.16" version = "0.3.17"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -121,6 +121,26 @@ fn trim_old_content(s: &str) -> String {
} }
} }
enum IncidentColorMap {
Update,
Investigating,
Monitoring,
Resolved,
Default
}
impl IncidentColorMap {
fn color(&self) -> u32 {
match self {
Self::Update => 0xABDD9E, // Madang
Self::Investigating => 0xA5CCE0, // French Pass
Self::Monitoring => 0x81CBAD, // Monte Carlo
Self::Resolved => 0x57F287, // Emerald
Self::Default => 0x81CBAD // Monte Carlo
}
}
}
pub async fn rss(ctx: Arc<Context>) -> Result<(), Error> { pub async fn rss(ctx: Arc<Context>) -> Result<(), Error> {
#[cfg(feature = "production")] #[cfg(feature = "production")]
let mut interval = interval(Duration::from_secs(300)); // Check feeds every 5 mins let mut interval = interval(Duration::from_secs(300)); // Check feeds every 5 mins

View File

@ -2,6 +2,7 @@ use crate::Error;
use super::{ use super::{
super::task_err, super::task_err,
REDIS_EXPIRY_SECS, REDIS_EXPIRY_SECS,
IncidentColorMap,
get_redis, get_redis,
save_to_redis, save_to_redis,
fetch_feed, fetch_feed,
@ -47,18 +48,21 @@ pub async fn github_embed() -> Result<Option<CreateEmbed>, Error> {
let color: u32; let color: u32;
let update_patt = Regex::new(r"(?i)\bupdate\b").unwrap(); let update_patt = Regex::new(r"(?i)\bupdate\b").unwrap();
let investigating_patt = Regex::new(r"(?i)\binvestigating\b").unwrap();
let resolved_patt = Regex::new(r"(?i)\bresolved\b").unwrap(); let resolved_patt = Regex::new(r"(?i)\bresolved\b").unwrap();
let date_patt = Regex::new(r"\b[A-Z][a-z]{2} \d{2}, \d{2}:\d{2} UTC\b").unwrap(); let date_patt = Regex::new(r"\b[A-Z][a-z]{2} \d{2}, \d{2}:\d{2} UTC\b").unwrap();
let first_entry = date_patt.split(&new_content).next().unwrap_or(&new_content); let first_entry = date_patt.split(&new_content).map(str::trim).find(|e| !e.is_empty()).unwrap_or(&new_content);
if update_patt.is_match(&first_entry) { color = if update_patt.is_match(&first_entry) {
color = 0xFFAD33; IncidentColorMap::Update.color()
} else if investigating_patt.is_match(&first_entry) {
IncidentColorMap::Investigating.color()
} else if resolved_patt.is_match(&first_entry) { } else if resolved_patt.is_match(&first_entry) {
color = 0x57F287; IncidentColorMap::Resolved.color()
} else { } else {
color = 0x243C32; IncidentColorMap::Default.color()
} };
if cached_incident.is_empty() { if cached_incident.is_empty() {
redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap(); redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap();

View File

@ -2,6 +2,7 @@ use crate::Error;
use super::{ use super::{
super::task_err, super::task_err,
REDIS_EXPIRY_SECS, REDIS_EXPIRY_SECS,
IncidentColorMap,
get_redis, get_redis,
save_to_redis, save_to_redis,
fetch_feed, fetch_feed,
@ -52,19 +53,19 @@ pub async fn gportal_embed() -> Result<Option<CreateEmbed>, Error> {
let resolved_patt = Regex::new(r"(?i)\bresolved\b").unwrap(); let resolved_patt = Regex::new(r"(?i)\bresolved\b").unwrap();
let date_patt = Regex::new(r"\b[A-Z][a-z]{2} \d{2}, \d{2}:\d{2} UTC\b").unwrap(); let date_patt = Regex::new(r"\b[A-Z][a-z]{2} \d{2}, \d{2}:\d{2} UTC\b").unwrap();
let first_entry = date_patt.split(&new_content).next().unwrap_or(&new_content); let first_entry = date_patt.split(&new_content).map(str::trim).find(|e| !e.is_empty()).unwrap_or(&new_content);
if update_patt.is_match(&first_entry) { color = if update_patt.is_match(&first_entry) {
color = 0xFFAD33; IncidentColorMap::Update.color()
} else if investigating_patt.is_match(&first_entry) { } else if investigating_patt.is_match(&first_entry) {
color = 0x16AAEB; IncidentColorMap::Investigating.color()
} else if monitoring_patt.is_match(&first_entry) { } else if monitoring_patt.is_match(&first_entry) {
color = 0x243C32; IncidentColorMap::Monitoring.color()
} else if resolved_patt.is_match(&first_entry) { } else if resolved_patt.is_match(&first_entry) {
color = 0x57F287; IncidentColorMap::Resolved.color()
} else { } else {
color = 0x243C32; IncidentColorMap::Default.color()
} };
if cached_incident.is_empty() { if cached_incident.is_empty() {
redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap(); redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap();