open-fbt/src/lib/memes.rs
2024-06-29 01:22:22 +10:00

77 lines
2.9 KiB
Rust
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::vars::FBT_GUILD_ID;
use once_cell::sync::Lazy;
use poise::serenity_prelude::{self as serenity};
use regex::Regex;
use strip_markdown::strip_markdown;
// Some times maybe good sometimes maybe shit
pub static POG_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"[pP𝓹𝖕𝔭𝕡ק🅟🅿ⓟρ𝙥քp̷þp͎₱ᵽ℘ア𝐩𝒑𝓅p̞̈͑̚͞℘p͓̽ք𝓹ᕶp̶p̳p̅][oO0øØ𝓸𝖔𝔬𝕠๏🅞🅾ⓞσOÒօoo̷ðo͎の𝗼ᵒ🇴𝙤ѻᓍӨo͓̽o͟o̲o̅o̳o̶🄾o̯̱̊͊͢Ꭷσ𝒐𝐨][gG9𝓰𝖌𝔤𝕘🅖🅶ⓖɠG𝑔ցg̷gg͎g̲g͟ǥ₲ɢg͓̽Gɠ𝓰𝙜🇬Ꮆᵍɢ𝗴𝐠𝒈𝑔ᧁg𝚐₲Ꮆ𝑔ĝ̽̓̀͑𝘨ງ🄶𝔤ģ]\b",
).unwrap()
});
/// This will read a message and check to see if the message contains the word `pog`
///
/// # Panics
///
/// Panics if regex fails to compile, this should be unreachable unless I acidentally change something before compile time.
///
/// # Errors
///
/// This function will return an error if .
pub async fn pog_be_gone(
new_message: &serenity::Message,
ctx: &serenity::Context,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if !new_message.author.bot && !new_message.content.is_empty() {
match new_message.guild(ctx) {
None => {} // Probably a DM, do nothing
Some(guild) => {
if guild.id.as_u64() == &FBT_GUILD_ID {
let lowercase_message = new_message.content.to_lowercase();
let cleaned_message = strip_markdown(&lowercase_message);
let words: Vec<&str> = cleaned_message.split(' ').collect();
let mut hits: Vec<&str> = Vec::new();
for word in words {
POG_RE.find(word).map_or((), |pog| {
hits.push(pog.as_str());
});
}
if !hits.is_empty() {
// there is at least 1 pog found
if hits.capacity().gt(&10) {
new_message
.reply(
ctx,
format!(
"Jesus dude, why did you pog {} times?! stop it!",
hits.len()
),
)
.await?;
} else {
new_message.reply_mention(ctx, "please refer to the rules and use the term 'poi' instead of 'pog'!").await?;
}
}
}
}
}
};
Ok(())
}
#[cfg(test)]
mod meme_tests {
use super::*;
#[test]
fn test_regex() {
let pog_test = "pog";
assert!(POG_RE.is_match(pog_test));
}
}