Add support for masks
This commit is contained in:
@@ -4,6 +4,8 @@ use once_cell::sync::Lazy;
|
||||
use rand::{SeedableRng, seq::IndexedRandom};
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
|
||||
use crate::utils::ToTitleCase;
|
||||
|
||||
static MASKS_COMMON: Lazy<HashMap<String, u64>> = Lazy::new(|| {
|
||||
let (file_name, json) = if cfg!(debug_assertions) {
|
||||
("dev/common.json", include_str!("dev/common.json"))
|
||||
@@ -11,8 +13,8 @@ static MASKS_COMMON: Lazy<HashMap<String, u64>> = Lazy::new(|| {
|
||||
("prod/common.json", include_str!("prod/common.json"))
|
||||
};
|
||||
|
||||
let masks: HashMap<String, u64> =
|
||||
serde_json::from_str(json).expect(&format!("Failed to parse masks/{file_name} masks"));
|
||||
let masks: HashMap<String, u64> = serde_json::from_str(json)
|
||||
.unwrap_or_else(|_| panic!("Failed to parse masks/{file_name} masks"));
|
||||
|
||||
assert_ne!(masks.len(), 0, "No masks found in masks/{file_name}");
|
||||
|
||||
@@ -30,3 +32,22 @@ pub fn get_random_mask(not_in: &[String]) -> Option<(String, u64)> {
|
||||
|
||||
mask_names.choose(&mut rng).cloned()
|
||||
}
|
||||
|
||||
pub fn get_mask_display_name(mask: impl ToString) -> String {
|
||||
mask.to_title_case()
|
||||
}
|
||||
|
||||
pub fn get_mask_emoji(mask: impl ToString) -> Option<String> {
|
||||
let emoji_name = mask.to_string().replace(" ", "");
|
||||
let emoji_id = MASKS_COMMON.get(&mask.to_string())?;
|
||||
|
||||
Some(format!("<:{emoji_name}:{emoji_id}>"))
|
||||
}
|
||||
|
||||
pub fn get_mask_avatar_url(mask: impl ToString) -> Option<String> {
|
||||
let mask_emoji_id = MASKS_COMMON.get(&mask.to_string())?;
|
||||
|
||||
Some(format!(
|
||||
"https://cdn.discordapp.com/emojis/{mask_emoji_id}.png?size=128&quality=lossless"
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user