From ab63110d01b9fd32a3fd31f7eb90356cf1258e61 Mon Sep 17 00:00:00 2001 From: ana_rchy Date: Sun, 2 Jun 2024 23:35:49 +0100 Subject: [PATCH] add easter egg reactions --- Cargo.lock | 15 +++++++++++++++ Cargo.toml | 1 + src/event.rs | 29 +++++++++++++---------------- src/global.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ec47a3..ff83458 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -413,6 +413,7 @@ version = "0.1.0" dependencies = [ "chrono-tz", "log", + "phf", "poise", "rand", "reqwest 0.12.4", @@ -1151,6 +1152,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ + "phf_macros", "phf_shared", ] @@ -1174,6 +1176,19 @@ dependencies = [ "rand", ] +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "phf_shared" version = "0.11.2" diff --git a/Cargo.toml b/Cargo.toml index 47e1b4b..7c95f2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] chrono-tz = "0.9.0" log = "0.4.21" +phf = { version = "0.11.2", features = ["macros"] } poise = "0.6.1" rand = "0.8.5" reqwest = { version = "0.12.4", features = ["json"] } diff --git a/src/event.rs b/src/event.rs index 6037bb0..fb0d52e 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,5 +1,6 @@ use crate::global::*; use std::sync::atomic::Ordering; +use std::str::FromStr; use poise::serenity_prelude::{self as serenity, CreateMessage, EmojiId, GuildRef, ReactionType}; use time::*; use log::{info, debug}; @@ -33,6 +34,8 @@ pub async fn event_handler( } serenity::FullEvent::Message { new_message } => { + easter_egg_reacts(&ctx, &new_message).await; + // early returns #[allow(dead_code)] const TESTING_CHANNEL_ID: u64 = 1235087573421133824; @@ -45,15 +48,11 @@ pub async fn event_handler( if !(current_time.time() > sunset_time.time() && current_time.hour() < 24) || !(new_message.channel_id == GENERAL_CHANNEL_ID || new_message.channel_id == TESTING_CHANNEL_ID) || new_message.author.id == BOT_ID + || !GOOD_EVENINGS.iter().any(|a| new_message.content.to_lowercase().contains(a)) { return Ok(()); } - if !GOOD_EVENINGS.iter().any(|a| new_message.content.to_lowercase().contains(a)) { - easter_egg_reacts(&ctx, &new_message).await; - return Ok(()); - } - // react to good evenings let reaction = ReactionType::Custom { @@ -106,17 +105,15 @@ pub async fn event_handler( } async fn easter_egg_reacts(ctx: &serenity::Context, message: &serenity::model::channel::Message) { - if !message.content.to_lowercase().contains("good morning") { - return; - } + for i in EASTER_EGG_REACTS.entries() { + if !message.content.contains(i.0) { + continue; + } - let reaction = ReactionType::Custom { - animated: true, - id: EmojiId::new(1218307823549546496), - name: Some("nerdo".to_string()), - }; - - message.react(&ctx.http, reaction).await.unwrap(); + let reaction = ReactionType::from_str(i.1).unwrap(); - debug!("easter egg reaction added"); + message.react(&ctx.http, reaction).await.unwrap(); + + debug!("easter egg reaction {} added", i.1); + } } diff --git a/src/global.rs b/src/global.rs index 84b4c72..fd685ec 100644 --- a/src/global.rs +++ b/src/global.rs @@ -2,6 +2,7 @@ use crate::web; use std::collections::HashMap; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex}; +use phf::phf_map; use tokio::sync as tsync; use log::info; @@ -64,6 +65,7 @@ pub static EVENING_MOTD: &[&str] = &[ "1% SUN 99% SET", "Are you the sun because you set everyday, or do you set everyday because you are the sun?", "Eight-Handled Sun Divergent Evening Divine General Eveningbot:", + "the evening knows when it is by knowing when it isnt", ]; pub static NIGHT_MOTD: &[&str] = &[ @@ -119,3 +121,27 @@ pub static GOOD_EVENINGS: &[&str] = &[ "goejun", "gott kveld", ]; + +pub static EASTER_EGG_REACTS: phf::Map<&str, &str> = phf_map!{ + "good morning" => "", + "kijetesantakalu" => "<:kijetesantakalu:1218305634563264572>", + "lesbiab" => "<:pls:1218307863613673573>", + "ana" => "<:ourdictator:1246936494548062302>", + "niko" => "<:ourdictator:1246936494548062302>", + "our dictator" => "<:ourdictator:1246936494548062302>", + "benevolent dictator for life" => "<:ourdictator:1246936494548062302>", + "shroom" => "", + "soko" => "", + "grzyb" => "", + "tiocfaidh ár lá" => "🇮🇪", // ie flag + "tiocfaidh ar la" => "🇮🇪", + "egg" => "", + "meow" => "", + "mrew" => "", + "mrow" => "", + "mraw" => "", + "nya" => "", + "nja" => "", + "moo" => "", + "whar" => "<:whar:1246955200200048703>", +};