more events
This commit is contained in:
parent
da022ed7b9
commit
2080fd9c77
|
@ -335,8 +335,8 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
|||
|
||||
[[package]]
|
||||
name = "furbooru"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/Xe/furbooru#175b0973dc0db4e4f385be2b94042e594859e5c7"
|
||||
version = "0.3.2"
|
||||
source = "git+https://github.com/Xe/furbooru#ad6980f212bc80811e048098dbc8b520c7a7dae2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
@ -1511,7 +1511,7 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
|
|||
|
||||
[[package]]
|
||||
name = "tron"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tron"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
authors = ["Christine Dodrill <me@christine.website>"]
|
||||
edition = "2018"
|
||||
repository = "https://tulpa.dev/cadey/tron"
|
||||
|
|
113
src/main.rs
113
src/main.rs
|
@ -49,7 +49,8 @@ impl fmt::Display for Hit {
|
|||
}
|
||||
}
|
||||
|
||||
struct Rules(Vec<CompiledRule>, Config);
|
||||
// TODO(Xe): make this an actual struct for the love of god.
|
||||
struct Rules(Vec<CompiledRule>, Config, furbooru::Client);
|
||||
|
||||
impl Rules {
|
||||
fn check(&self, text: &String) -> Option<Vec<Hit>> {
|
||||
|
@ -73,6 +74,12 @@ impl Rules {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
async fn tell(&self, message: String) -> Result<()> {
|
||||
discord_webhook::execute(self.1.discord_webhook_url.clone(), Body::new(message)).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -86,22 +93,50 @@ impl FirehoseAdaptor for Rules {
|
|||
for hit in hits {
|
||||
buf.push_str(&format!("\n{}", hit));
|
||||
}
|
||||
discord_webhook::execute(
|
||||
self.1.discord_webhook_url.clone(),
|
||||
Body::new(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
img.uploader.or(Some("An anonymous user".into())).unwrap(),
|
||||
url,
|
||||
buf
|
||||
)),
|
||||
)
|
||||
|
||||
self.tell(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
img.uploader.or(Some("An anonymous user".into())).unwrap(),
|
||||
url,
|
||||
buf
|
||||
))
|
||||
.await?;
|
||||
|
||||
log::info!("the description of {} has naughty words", url);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn image_description_updated(
|
||||
&self,
|
||||
id: u64,
|
||||
added: String,
|
||||
_removed: String,
|
||||
) -> Result<()> {
|
||||
let url = format!("https://furbooru.org/{}", id);
|
||||
|
||||
if let Some(hits) = self.check(&added.to_lowercase()) {
|
||||
let mut buf: String = String::new();
|
||||
|
||||
for hit in hits {
|
||||
buf.push_str(&format!("\n{}", hit));
|
||||
}
|
||||
|
||||
let img = self.2.image(id.clone()).await?;
|
||||
|
||||
self.tell(format!(
|
||||
"description of <{url}> from **{who}** matches:{why}",
|
||||
who = img.uploader.or(Some("An anonymous user".into())).unwrap(),
|
||||
url = url,
|
||||
why = buf
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn comment_created(&self, cmt: Comment) -> Result<()> {
|
||||
let url = format!("https://furbooru.org/{}#comment_{}", cmt.image_id, cmt.id);
|
||||
log::debug!("got comment {}", url);
|
||||
|
@ -111,13 +146,30 @@ impl FirehoseAdaptor for Rules {
|
|||
for hit in hits {
|
||||
buf.push_str(&format!("\n{}", hit));
|
||||
}
|
||||
discord_webhook::execute(
|
||||
self.1.discord_webhook_url.clone(),
|
||||
Body::new(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
cmt.author, url, buf
|
||||
)),
|
||||
)
|
||||
self.tell(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
cmt.author, url, buf
|
||||
))
|
||||
.await?;
|
||||
log::info!("comment {} has naughty words", url);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn comment_updated(&self, cmt: Comment) -> Result<()> {
|
||||
let url = format!("https://furbooru.org/{}#comment_{}", cmt.image_id, cmt.id);
|
||||
log::debug!("got comment update {}", url);
|
||||
if let Some(hits) = self.check(&cmt.body.to_lowercase()) {
|
||||
let mut buf: String = String::new();
|
||||
|
||||
for hit in hits {
|
||||
buf.push_str(&format!("\n{}", hit));
|
||||
}
|
||||
self.tell(format!(
|
||||
"matches from **{}** found on updated comment <{}>:{}",
|
||||
cmt.author, url, buf
|
||||
))
|
||||
.await?;
|
||||
log::info!("comment {} has naughty words", url);
|
||||
}
|
||||
|
@ -140,13 +192,10 @@ impl FirehoseAdaptor for Rules {
|
|||
for hit in hits {
|
||||
buf.push_str(&format!("\n{}", hit));
|
||||
}
|
||||
discord_webhook::execute(
|
||||
self.1.discord_webhook_url.clone(),
|
||||
Body::new(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
pst.author, url, buf
|
||||
)),
|
||||
)
|
||||
self.tell(format!(
|
||||
"matches from **{}** found on <{}>:{}",
|
||||
pst.author, url, buf
|
||||
))
|
||||
.await?;
|
||||
log::info!("post {} has naughty words", url);
|
||||
}
|
||||
|
@ -170,7 +219,11 @@ async fn main() -> Result<()> {
|
|||
{
|
||||
discord_webhook::execute(
|
||||
cfg.discord_webhook_url.clone(),
|
||||
Body::new("I fight for the user!"),
|
||||
Body::new(format!(
|
||||
"I fight for the user! {} version {} active",
|
||||
env!("CARGO_PKG_NAME"),
|
||||
env!("CARGO_PKG_VERSION")
|
||||
)),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -189,7 +242,15 @@ async fn main() -> Result<()> {
|
|||
cfg.furbooru_api_key.clone(),
|
||||
)?;
|
||||
log::info!("listening on the firehose");
|
||||
cli.firehose(Rules(compiled_rules, cfg)).await?;
|
||||
cli.firehose(Rules(
|
||||
compiled_rules,
|
||||
cfg.clone(),
|
||||
Client::new(
|
||||
user_agent(cfg.bot_owner_furbooru_account.clone()),
|
||||
cfg.furbooru_api_key.clone(),
|
||||
)?,
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue