diff --git a/src/data/bot_data.rs b/src/data/bot_data.rs index 00cad5f..3ef4f57 100644 --- a/src/data/bot_data.rs +++ b/src/data/bot_data.rs @@ -1,4 +1,6 @@ -use crate::enums::schemas::DatabaseSchema; +use crate::{ + enums::schemas::DatabaseSchema, utils::string_manipulation::upper_lowercase_permutations, +}; use std::collections::HashMap; use lazy_static::lazy_static; @@ -24,4 +26,11 @@ lazy_static! { ]) }; pub(crate) static ref XP_COOLDOWN_NUMBER_SECS: i64 = 60; + pub(crate) static ref BOT_PREFIXES: Vec = { + let mut temp = vec![]; + temp.append(&mut upper_lowercase_permutations("hu")); + temp.append(&mut upper_lowercase_permutations("ht")); + + temp + }; } diff --git a/src/lib.rs b/src/lib.rs index 4b993fe..348f5ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,5 +3,5 @@ pub mod data; pub mod enums; pub mod event_handler; pub mod extra_threads; -pub mod structs; pub mod tests; +pub mod utils; diff --git a/src/main.rs b/src/main.rs index 9cdb5d4..834644e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ mod commands; // use commands::general_commands::*; mod data; -use data::bot_data::{BOT_TOKEN, START_TIME}; +use data::bot_data::{BOT_PREFIXES, BOT_TOKEN, START_TIME}; use data::command_data::Data; mod enums; @@ -62,8 +62,7 @@ use extra_threads::xp_command_cooldown::periodically_clean_users_on_diff_thread; mod event_handler; use event_handler::handler::event_handler; -mod structs; -use structs::CmdPrefixes; +mod utils; mod tests; @@ -80,8 +79,6 @@ use std::sync::Arc; async fn main() { let _ = START_TIME.elapsed().as_secs(); // Dummy data to get the time elapsing started - let bot_prefixes = CmdPrefixes::set(); - dotenv::dotenv().ok(); periodically_clean_users_on_diff_thread(); let token = BOT_TOKEN.to_string(); @@ -154,10 +151,9 @@ async fn main() { prefix_options: poise::PrefixFrameworkOptions { prefix: None, - additional_prefixes: bot_prefixes - .prefixes + additional_prefixes: BOT_PREFIXES .iter() - .map(|x| poise::Prefix::Literal(x.to_owned())) + .map(|x| poise::Prefix::Literal(x.as_str())) .collect::>(), mention_as_prefix: true, case_insensitive_commands: true, @@ -214,8 +210,7 @@ async fn main() { // ) .activity(serenity::ActivityData::custom(format!( "Usable prefixes: [ {} ]", - bot_prefixes - .prefixes + BOT_PREFIXES .iter() .filter(|&x| x.chars().all(|c| c.is_lowercase())) .map(|x| x.to_string()) diff --git a/src/structs/mod.rs b/src/structs/mod.rs deleted file mode 100644 index acfea8a..0000000 --- a/src/structs/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[derive(Debug, Default)] -pub struct CmdPrefixes { - pub prefixes: Vec<&'static str>, -} -impl CmdPrefixes { - pub fn set() -> Self { - Self { - prefixes: vec!["hu", "Hu", "hU", "HU", "ht", "Ht", "hT", "HT"], - } - } -} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 0084150..092c808 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -24,10 +24,8 @@ fn normal_types() { use crate::data::command_data::Data; use crate::enums::command_enums::EmbedType; use crate::enums::schemas::DatabaseSchema; - use crate::structs::CmdPrefixes; _is_normal::(); _is_normal::(); _is_normal::(); - _is_normal::(); } diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..2297a3a --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod string_manipulation; diff --git a/src/utils/string_manipulation.rs b/src/utils/string_manipulation.rs new file mode 100644 index 0000000..15e1e0f --- /dev/null +++ b/src/utils/string_manipulation.rs @@ -0,0 +1,19 @@ +pub fn upper_lowercase_permutations(data: &str) -> Vec { + if data.is_empty() { + return vec![String::new()]; + } + + let first = data.chars().next().unwrap(); + let rest = &data[1..]; + + let permutations = upper_lowercase_permutations(rest); + + let mut result: Vec = Vec::new(); + + for perm in permutations { + result.push(format!("{}{}", first.to_ascii_lowercase(), perm)); + result.push(format!("{}{}", first.to_ascii_uppercase(), perm)); + } + + result +}