aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Audron <me@audron.dev>2025-12-17 23:55:02 +0100
committerMax Audron <me@audron.dev>2025-12-17 23:55:02 +0100
commitcdece050ff66db48021c3d4010d252b459dcb762 (patch)
tree9cfd2236ddc85fba57a32dcc5919c413eb66cb2c
parentupdate debug config files (diff)
add twitter cancel feature
yeah nitter
-rw-r--r--src/hooks/mod.rs2
-rw-r--r--src/hooks/nitter.rs29
-rw-r--r--src/main.rs20
3 files changed, 44 insertions, 7 deletions
diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs
index d70af9c..39198c1 100644
--- a/src/hooks/mod.rs
+++ b/src/hooks/mod.rs
@@ -7,10 +7,12 @@ use base64::{alphabet, engine, Engine};
use irc::client::prelude::*;
mod intensify;
+mod nitter;
mod pet;
mod shifty_eyes;
pub use intensify::*;
+pub use nitter::*;
pub use pet::*;
pub use shifty_eyes::*;
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(())
+}
diff --git a/src/main.rs b/src/main.rs
index e4c65d0..f180ea3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ async fn main() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
- // .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
+ .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
rustls::crypto::CryptoProvider::install_default(rustls::crypto::aws_lc_rs::default_provider())
@@ -17,12 +17,12 @@ async fn main() {
.expect("failed to initialize WolframAlpha command");
catinator![
- hook(
- "sasl",
- "Handle Authentication.",
- AUTHENTICATE,
- catinator::hooks::sasl
- ),
+ // hook(
+ // "sasl",
+ // "Handle Authentication.",
+ // AUTHENTICATE,
+ // catinator::hooks::sasl
+ // ),
hook(
"sed_log",
"Log messages for use with sed replace, max 10k lines.",
@@ -30,6 +30,12 @@ async fn main() {
sed.log
),
matcher(
+ "nitter",
+ "replace twitter urls with a nitter instance (xcancel.com)",
+ r"https:\/\/(twitter|x)\.com\/",
+ catinator::hooks::nitter
+ ),
+ matcher(
"shifty_eyes",
">.>",
r"^\S{3}$",