Add IncidentColorMap enum
This commit is contained in:
parent
1fa75a4d6f
commit
dfa1ae75b2
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1023,7 +1023,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kon"
|
||||
version = "0.3.16"
|
||||
version = "0.3.17"
|
||||
dependencies = [
|
||||
"bb8",
|
||||
"bb8-postgres",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "kon"
|
||||
version = "0.3.16"
|
||||
version = "0.3.17"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
@ -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> {
|
||||
#[cfg(feature = "production")]
|
||||
let mut interval = interval(Duration::from_secs(300)); // Check feeds every 5 mins
|
||||
|
@ -2,6 +2,7 @@ use crate::Error;
|
||||
use super::{
|
||||
super::task_err,
|
||||
REDIS_EXPIRY_SECS,
|
||||
IncidentColorMap,
|
||||
get_redis,
|
||||
save_to_redis,
|
||||
fetch_feed,
|
||||
@ -47,18 +48,21 @@ pub async fn github_embed() -> Result<Option<CreateEmbed>, Error> {
|
||||
|
||||
let color: u32;
|
||||
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 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 = 0xFFAD33;
|
||||
color = if update_patt.is_match(&first_entry) {
|
||||
IncidentColorMap::Update.color()
|
||||
} else if investigating_patt.is_match(&first_entry) {
|
||||
IncidentColorMap::Investigating.color()
|
||||
} else if resolved_patt.is_match(&first_entry) {
|
||||
color = 0x57F287;
|
||||
IncidentColorMap::Resolved.color()
|
||||
} else {
|
||||
color = 0x243C32;
|
||||
}
|
||||
IncidentColorMap::Default.color()
|
||||
};
|
||||
|
||||
if cached_incident.is_empty() {
|
||||
redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap();
|
||||
|
@ -2,6 +2,7 @@ use crate::Error;
|
||||
use super::{
|
||||
super::task_err,
|
||||
REDIS_EXPIRY_SECS,
|
||||
IncidentColorMap,
|
||||
get_redis,
|
||||
save_to_redis,
|
||||
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 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 = 0xFFAD33;
|
||||
color = if update_patt.is_match(&first_entry) {
|
||||
IncidentColorMap::Update.color()
|
||||
} else if investigating_patt.is_match(&first_entry) {
|
||||
color = 0x16AAEB;
|
||||
IncidentColorMap::Investigating.color()
|
||||
} else if monitoring_patt.is_match(&first_entry) {
|
||||
color = 0x243C32;
|
||||
IncidentColorMap::Monitoring.color()
|
||||
} else if resolved_patt.is_match(&first_entry) {
|
||||
color = 0x57F287;
|
||||
IncidentColorMap::Resolved.color()
|
||||
} else {
|
||||
color = 0x243C32;
|
||||
}
|
||||
IncidentColorMap::Default.color()
|
||||
};
|
||||
|
||||
if cached_incident.is_empty() {
|
||||
redis.set(&rkey, &get_incident_id(&article.links[0].href).unwrap()).await.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user