From bb3df7e6ab9de4c52fbe81b589ac5d1add6d281d Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 7 Apr 2023 19:59:19 -0400 Subject: add random lore command --- src/utils.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 4157e3b..bb57521 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,16 +9,29 @@ 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(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 -- cgit v1.2.3