summaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 4157e3b..bb57521 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -9,17 +9,30 @@ const CHAR_LIMIT: usize = 2000;
const FILES: Dir = include_dir!("src/include");
/*
- * chooses a random response out of our options
+ * chooses a random element from an array
*/
-pub async fn get_random_response() -> String {
+async fn random_choice<const N: usize>(arr: [&str; N]) -> String {
let mut rng = rand::thread_rng();
- let resp = RESPONSES
+ let resp = arr
.choose(&mut rng)
.expect("couldn't choose random value!");
resp.to_string()
}
/*
+ * pub functions to get random elements
+ * from our consts
+ */
+
+pub async fn get_random_response() -> String {
+ random_choice(RESPONSES).await
+}
+
+pub async fn get_random_lore() -> String {
+ random_choice(LORE).await
+}
+
+/*
* splits a message into multiple parts so that
* it can fit discord's character limit
*/