diff --git a/src/consts.rs b/src/consts.rs index 3e9f541..5a0aa29 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -13,22 +13,3 @@ pub static COLORS: Lazy> = Lazy::new(|| { // TODO purple & pink :D ]) }); - -pub const ETA_MESSAGES: [&str; 16] = [ - "Sometime", - "Some day", - "Not far", - "The future", - "Never", - "Perhaps tomorrow?", - "There are no ETAs", - "No", - "Nah", - "Yes", - "Yas", - "Next month", - "Next year", - "Next week", - "In Prism Launcher 2.0.0", - "At the appropriate juncture, in due course, in the fullness of time", -]; diff --git a/src/handlers/event/eta.rs b/src/handlers/event/eta.rs index 8480189..dcf9dbe 100644 --- a/src/handlers/event/eta.rs +++ b/src/handlers/event/eta.rs @@ -1,12 +1,30 @@ -use crate::{consts, utils}; - use color_eyre::eyre::Result; use once_cell::sync::Lazy; use poise::serenity_prelude::{Context, Message}; +use rand::seq::SliceRandom; use regex::Regex; static ETA_REGEX: Lazy = Lazy::new(|| Regex::new(r"\beta\b").unwrap()); +pub const ETA_MESSAGES: [&str; 16] = [ + "Sometime", + "Some day", + "Not far", + "The future", + "Never", + "Perhaps tomorrow?", + "There are no ETAs", + "No", + "Nah", + "Yes", + "Yas", + "Next month", + "Next year", + "Next week", + "In Prism Launcher 2.0.0", + "At the appropriate juncture, in due course, in the fullness of time", +]; + pub async fn handle(ctx: &Context, message: &Message) -> Result<()> { if !ETA_REGEX.is_match(&message.content) { return Ok(()); @@ -14,7 +32,9 @@ pub async fn handle(ctx: &Context, message: &Message) -> Result<()> { let response = format!( "{} <:pofat:1031701005559144458>", - utils::random_choice(consts::ETA_MESSAGES)? + ETA_MESSAGES + .choose(&mut rand::thread_rng()) + .unwrap_or(&"sometime") ); message.reply(ctx, response).await?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 7592306..8cfb89f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,18 +1,3 @@ -use color_eyre::eyre::{eyre, Result}; -use rand::seq::SliceRandom; - mod resolve_message; pub use resolve_message::resolve as resolve_message; - -/* - * chooses a random element from an array - */ -pub fn random_choice(arr: [&str; N]) -> Result { - let mut rng = rand::thread_rng(); - let resp = arr - .choose(&mut rng) - .ok_or_else(|| eyre!("Couldn't choose random object from array:\n{arr:#?}!"))?; - - Ok((*resp).to_string()) -}