diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-11-24 11:04:29 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-11-24 11:04:29 -0600 |
commit | 6704dcb51c9de5c66102600d06ffe637fd2db7c1 (patch) | |
tree | 15c9e68f9ee32146bbb007a355f4d911616db784 /src/quit_twitter.rs | |
parent | dd0e6e45c35133ec8a3e2886b7b050484b388d03 (diff) |
Adds plugin to encourage the quitting of Twitter. Eh, it's a tradition at this point.
Diffstat (limited to 'src/quit_twitter.rs')
-rw-r--r-- | src/quit_twitter.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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<ControlFlow<(), ()>> { + 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(())) +} |