Fix peko detection and add random rare pekos

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/2/head
trivernis 3 years ago
parent 60f300913d
commit 62d9664b35
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,10 +1,18 @@
use rand::prelude::*;
use regex::Regex; use regex::Regex;
use serenity::framework::standard::{Args, CommandError, CommandResult}; use serenity::framework::standard::{Args, CommandError, CommandResult};
use serenity::model::channel::Message; use serenity::model::channel::Message;
use serenity::{framework::standard::macros::command, prelude::*}; use serenity::{framework::standard::macros::command, prelude::*};
#[allow(dead_code)] // return a normal peko in most cases
static MESSAGE_DELIMITERS: &[char] = &['.', '?', '!', '"']; static PEKOS: &[&str] = &[
"peko",
"p e k o",
"peeeeekooooo",
"pppeeekkkooo",
"🇵 🇪 🇰 🇴",
"p3k0",
];
#[command] #[command]
#[description("Pekofy messages")] #[description("Pekofy messages")]
@ -43,6 +51,8 @@ async fn pekofy(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let pekofied: String = if alpha_lowercase == "pain" { let pekofied: String = if alpha_lowercase == "pain" {
"https://tenor.com/view/pekora-usada-peko-hololive-died-gif-18114577".to_string() "https://tenor.com/view/pekora-usada-peko-hololive-died-gif-18114577".to_string()
} else if PEKOS.contains(&&*alpha_lowercase) {
random_peko()
} else { } else {
content content
.lines() .lines()
@ -64,7 +74,7 @@ async fn pekofy(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
/// Pekofies a single line /// Pekofies a single line
fn pekofy_line(mut line: &str) -> String { fn pekofy_line(mut line: &str) -> String {
lazy_static::lazy_static! { static ref FORMATTING_REGEX: Regex = Regex::new(r"^(.*?)((<:\w+:\d+>|\W)+)$").unwrap(); } lazy_static::lazy_static! { static ref FORMATTING_REGEX: Regex = Regex::new(r"^(.*?)((<:\w+:\d+>|\W)*)$").unwrap(); }
log::debug!("Pekofying line '{}'", line); log::debug!("Pekofying line '{}'", line);
let original = line; let original = line;
@ -74,12 +84,14 @@ fn pekofy_line(mut line: &str) -> String {
md = captures.get(2).unwrap().as_str(); md = captures.get(2).unwrap().as_str();
} }
if line.ends_with("peko") { for peko in PEKOS {
log::debug!("Peko already found in message. Returning original"); if line.to_lowercase().ends_with(peko) {
return original.to_string(); log::debug!("Peko already found in message. Returning original");
return original.to_string();
}
} }
let mut peko = "peko".to_string(); let mut peko = random_peko();
if line if line
.chars() .chars()
@ -92,3 +104,13 @@ fn pekofy_line(mut line: &str) -> String {
format!("{} {}{}", line, peko, md) format!("{} {}{}", line, peko, md)
} }
/// Returns a random peko
fn random_peko() -> String {
let mut rng = rand::thread_rng();
if rng.gen_range(0..20) == 10 {
PEKOS.choose(&mut rng).unwrap().to_string()
} else {
"peko".to_string()
}
}

Loading…
Cancel
Save