once_cell -> std

This commit is contained in:
seth 2024-03-30 03:04:32 -04:00
parent a41a84fd2d
commit 90387c5a3b
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
28 changed files with 157 additions and 153 deletions

View file

@ -1,13 +1,17 @@
use std::sync::OnceLock;
use eyre::Result;
use log::trace;
use once_cell::sync::Lazy;
use poise::serenity_prelude::{Context, Message};
use rand::seq::SliceRandom;
use regex::Regex;
static ETA_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\beta\b").unwrap());
fn regex() -> &'static Regex {
static REGEX: OnceLock<Regex> = OnceLock::new();
REGEX.get_or_init(|| Regex::new(r"\beta\b").unwrap())
}
const ETA_MESSAGES: [&str; 16] = [
const MESSAGES: [&str; 16] = [
"Sometime",
"Some day",
"Not far",
@ -27,7 +31,7 @@ const ETA_MESSAGES: [&str; 16] = [
];
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
if !ETA_REGEX.is_match(&message.content) {
if !regex().is_match(&message.content) {
trace!(
"The message '{}' (probably) doesn't say ETA",
message.content
@ -37,7 +41,7 @@ pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
let response = format!(
"{} <:pofat:1031701005559144458>",
ETA_MESSAGES
MESSAGES
.choose(&mut rand::thread_rng())
.unwrap_or(&"sometime")
);