diff --git a/Cargo.lock b/Cargo.lock index 3149b46..12e1e17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "0.2.3" @@ -29,6 +31,7 @@ name = "basedbot" version = "0.1.0" dependencies = [ "lazy_static", + "regex", "serenity", ] @@ -487,9 +490,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.3.3" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" @@ -746,6 +749,21 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + [[package]] name = "reqwest" version = "0.10.8" diff --git a/Cargo.toml b/Cargo.toml index 093a390..901ffad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,7 @@ version = "0.1.0" authors = ["kageru "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] serenity = "0.8.7" lazy_static = "1.4.0" +regex = { version = "1.5.6", default_features = false, features = ["std", "unicode"] } diff --git a/src/main.rs b/src/main.rs index efc0f2b..0fe3b45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ +use lazy_static::lazy_static; +use regex::{Captures, Regex}; use serenity::model::channel::ReactionType; use serenity::model::id::{ChannelId, EmojiId, GuildId}; use serenity::model::prelude::*; use serenity::prelude::*; use serenity::Client; -#[macro_use] -extern crate lazy_static; struct Handler; @@ -12,6 +12,7 @@ lazy_static! { static ref SERVER_ID: GuildId = GuildId(std::env::args().nth(1).unwrap().parse().unwrap()); static ref MEME_CHANNEL: ChannelId = ChannelId(std::env::args().nth(2).unwrap().parse().unwrap()); + static ref RETARD_REGEX: Regex = Regex::new("([^j])a( |$)").unwrap(); } impl EventHandler for Handler { @@ -19,6 +20,26 @@ impl EventHandler for Handler { if message.guild_id != Some(*SERVER_ID) { return; } + // That other idiot who ends words with β€œa” instead of β€œer” + if message.author.id == 261246789942902794 && RETARD_REGEX.is_match(&message.content) { + if let Err(e) = message.delete(&ctx) { + eprintln!("Could not delete retarded message: {e}"); + } + if let Err(e) = message + .channel_id + .say(&ctx, &format!("{} wollte sagen:", message.author.mention())) + { + eprint!("Could not send sanitized message intro: {e}"); + } + if let Err(e) = message.channel_id.say( + &ctx, + RETARD_REGEX.replace_all(&message.content_safe(&ctx), |caps: &Captures| { + format!("{}**er**{}", &caps[1], &caps[2]) + }), + ) { + eprint!("Could not send sanitized message: {e}"); + } + } if message.author.id != 733488485813584012 // that one idiot who always posts 5 links per message && message.content.contains("https://media.discordapp.net/") && (message.content.contains(".mp4") @@ -26,7 +47,7 @@ impl EventHandler for Handler { || message.content.contains(".mov")) { if let Err(e) = message.channel_id.say(&ctx, "Working link:") { - eprint!("Could not send fixed link: {:?}", e); + eprint!("Could not send fixed link: {e}"); } if let Err(e) = message.channel_id.say( &ctx, @@ -35,7 +56,7 @@ impl EventHandler for Handler { "https://cdn.discordapp.com/", ), ) { - eprint!("Could not send fixed link: {:?}", e); + eprint!("Could not send fixed link: {e}"); }; } if message.channel_id == *MEME_CHANNEL && is_meme(&message) { @@ -45,13 +66,13 @@ impl EventHandler for Handler { let content = message.content.to_lowercase(); if content.contains("everyone") && content.contains("nitro") && content.contains("http") { if let Err(e) = message.delete(&ctx) { - eprint!("Could not delete spam: {}", e); + eprint!("Could not delete spam: {e}"); } if let Err(e) = message.channel_id.say( &ctx, &format!("{}: your message has been deleted because it triggered my spam filter. If you believe this to be in error, please contact the mods.", message.author.mention()) ) { - eprint!("Could not respond to spam: {}", e); + eprint!("Could not respond to spam: {e}"); } } } @@ -64,7 +85,7 @@ fn react(ctx: &Context, msg: &Message, emoji: u64, name: &str) { name: Some(name.to_string()), }; if let Err(e) = msg.react(ctx, reaction) { - println!("Could not react, error was: {:?}", e); + println!("Could not react, error was: {e}"); } }