From 6704dcb51c9de5c66102600d06ffe637fd2db7c1 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Sun, 24 Nov 2024 11:04:29 -0600 Subject: Adds plugin to encourage the quitting of Twitter. Eh, it's a tradition at this point. --- src/quit_twitter.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/quit_twitter.rs (limited to 'src/quit_twitter.rs') diff --git a/src/quit_twitter.rs b/src/quit_twitter.rs new file mode 100644 index 0000000..fdeee94 --- /dev/null +++ b/src/quit_twitter.rs @@ -0,0 +1,33 @@ +use crate::HandlerConfig; +use anyhow::{anyhow, Context as _, Result}; +use serenity::all::{Context, Message}; +use std::ops::ControlFlow; + +const TWITTER_URLS: &[&str] = &[ + "https://fixupx.com/", + "https://fixvx.com/", + "https://pbs.twimg.com/", + "https://t.co/", + "https://twitter.com/", + "https://x.com/", +]; + +const REACTS: &[char] = &['🇶', '🇺', '🇮', '🇹', '🐦']; + +pub async fn on_message( + config: &HandlerConfig, + ctx: &Context, + msg: &Message, +) -> Result> { + let is_twitter = TWITTER_URLS.iter().any(|url| msg.content.contains(url)); + if !is_twitter { + return Ok(ControlFlow::Continue(())); + } + + for &react in REACTS { + msg.react(&ctx.http, react) + .await + .with_context(|| anyhow!("Failed to react with {react} on a Twitter message"))?; + } + Ok(ControlFlow::Break(())) +} -- cgit v1.2.3