refine messaging

This commit is contained in:
Cadey Ratio 2020-07-03 20:52:52 -04:00
parent 11ed808373
commit ecdcbab6dc
2 changed files with 10 additions and 7 deletions

View File

@ -3,4 +3,6 @@ let Rule =
, default = { regex = "", why = "" }
}
in [ Rule::{ regex = "(n|z)igg(er|a)", why = "racism" } ]
in [ Rule::{ regex = "(n|z)igg(er|a)", why = "racism" }
, Rule::{ regex = "(hot|cute)", why = "Cadey is testing" }
]

View File

@ -46,16 +46,16 @@ impl FirehoseAdaptor for Rules {
let mut found = false;
for rule in &self.0 {
if rule.regex.is_match(&img.description) {
if rule.regex.is_match(&img.description.to_lowercase()) {
found = true;
buf.push_str(&format!("\n- match on rule {} ({})", rule.raw, rule.why));
buf.push_str(&format!("\n- match on rule `{}` ({})", rule.raw, rule.why));
}
}
if found {
discord_webhook::execute(
self.1.discord_webhook_url.clone(),
Body::new(format!("matches found on {}: \n{}", img.view_url, buf)),
Body::new(format!("matches found on <{}>:{}", img.view_url, buf)),
)
.await?;
}
@ -68,9 +68,9 @@ impl FirehoseAdaptor for Rules {
let mut found = false;
for rule in &self.0 {
if rule.regex.is_match(&cmt.body) {
if rule.regex.is_match(&cmt.body.to_lowercase()) {
found = true;
buf.push_str(&format!("\n- match on rule {} ({})", rule.raw, rule.why));
buf.push_str(&format!("\n- match on rule `{}` ({})", rule.raw, rule.why));
}
}
@ -78,7 +78,7 @@ impl FirehoseAdaptor for Rules {
discord_webhook::execute(
self.1.discord_webhook_url.clone(),
Body::new(format!(
"matches found on https://furbooru.org/{}#comment_{}: \n{}",
"matches found on <https://furbooru.org/{}#comment_{}>:{}",
cmt.image_id, cmt.id, buf
)),
)
@ -98,6 +98,7 @@ async fn main() -> Result<()> {
let mut compiled_rules: Vec<CompiledRule> = Vec::new();
for rule in rexes {
println!("{} -> {}", rule.regex, rule.why);
compiled_rules.push(CompiledRule {
raw: rule.regex.clone(),
regex: Regex::new(rule.regex.as_str())?,