diff options
| author | Max Audron <me@audron.dev> | 2025-12-17 23:55:02 +0100 |
|---|---|---|
| committer | Max Audron <me@audron.dev> | 2025-12-17 23:55:02 +0100 |
| commit | cdece050ff66db48021c3d4010d252b459dcb762 (patch) | |
| tree | 9cfd2236ddc85fba57a32dcc5919c413eb66cb2c /src/hooks/nitter.rs | |
| parent | update debug config files (diff) | |
add twitter cancel feature
yeah nitter
Diffstat (limited to 'src/hooks/nitter.rs')
| -rw-r--r-- | src/hooks/nitter.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/hooks/nitter.rs b/src/hooks/nitter.rs new file mode 100644 index 0000000..f29e885 --- /dev/null +++ b/src/hooks/nitter.rs @@ -0,0 +1,29 @@ +use std::sync::LazyLock; + +use anyhow::{Context, Result}; +use irc::client::prelude::*; +use regex::Regex; + +static RE: LazyLock<Regex> = + LazyLock::new(|| Regex::new(r"https:\/\/(?:twitter|x)\.com\/(\S+?)(?:\s|$)").unwrap()); + +const URL: &str = "https://xcancel.com/"; + +pub fn nitter(bot: &crate::Bot, msg: Message) -> Result<()> { + if let Command::PRIVMSG(_, text) = msg.command.clone() { + let path = RE + .captures(&text) + .context("failed to capture twitter url path")? + .get(1) + .context("failed to get path capture group")? + .as_str(); + + bot.send_privmsg( + msg.response_target() + .context("failed to get response target")?, + format!("get cancled {URL}{path}").as_str(), + )?; + } + + Ok(()) +} |
