49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
//! this rust smells of java and i find that hilarious
|
|
|
|
use std::{fs, ops::DerefMut, sync::LazyLock};
|
|
|
|
use rand::random_range;
|
|
|
|
static MEOWER: Meower = Meower {
|
|
meows: LazyLock::new(|| {
|
|
let file = fs::read_to_string("meows.txt");
|
|
if let Ok(content) = file {
|
|
Some(
|
|
content
|
|
.lines()
|
|
.filter(|ln| !ln.is_empty())
|
|
.map(|s| s.trim().to_owned())
|
|
.collect(),
|
|
)
|
|
} else {
|
|
None
|
|
}
|
|
}),
|
|
};
|
|
|
|
pub struct Meower {
|
|
meows: LazyLock<Option<Vec<String>>>,
|
|
}
|
|
|
|
impl Meower {
|
|
pub fn get() -> Option<&'static Self> {
|
|
MEOWER.meows.is_some().then_some(&MEOWER)
|
|
}
|
|
|
|
// this is rancid
|
|
pub fn meow(&self) -> String {
|
|
self.meows
|
|
.clone()
|
|
.map(|meows| meows[random_range(0..meows.len())].clone())
|
|
.clone()
|
|
.expect("meows existence should be checked on init")
|
|
.to_owned()
|
|
}
|
|
|
|
pub fn check_if_meow(&self, item: &str) -> bool {
|
|
if let Some(meows) = &*self.meows {
|
|
return meows.iter().any(|it| *it == item.trim().to_lowercase());
|
|
}
|
|
false
|
|
}
|
|
}
|