Skip to content

Commit

Permalink
add easter egg reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-rchy committed Jun 2, 2024
1 parent e69f83d commit ab63110
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
29 changes: 13 additions & 16 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
26 changes: 26 additions & 0 deletions src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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] = &[
Expand Down Expand Up @@ -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" => "<a:nerdo:1218307823549546497>",
"kijetesantakalu" => "<:kijetesantakalu:1218305634563264572>",
"lesbiab" => "<:pls:1218307863613673573>",
"ana" => "<:ourdictator:1246936494548062302>",
"niko" => "<:ourdictator:1246936494548062302>",
"our dictator" => "<:ourdictator:1246936494548062302>",
"benevolent dictator for life" => "<:ourdictator:1246936494548062302>",
"shroom" => "<a:mushroomdance:1218307936271728680>",
"soko" => "<a:mushroomdance:1218307936271728680>",
"grzyb" => "<a:mushroomdance:1218307936271728680>",
"tiocfaidh ár lá" => "🇮🇪", // ie flag
"tiocfaidh ar la" => "🇮🇪",
"egg" => "<a:eggblush:1218305920119865484>",
"meow" => "<a:catkiss:1218306966301184040>",
"mrew" => "<a:catkiss:1218306966301184040>",
"mrow" => "<a:catkiss:1218306966301184040>",
"mraw" => "<a:catkiss:1218306966301184040>",
"nya" => "<a:catkiss:1218306966301184040>",
"nja" => "<a:catkiss:1218306966301184040>",
"moo" => "<a:krowa:1218306885824807103>",
"whar" => "<:whar:1246955200200048703>",
};

0 comments on commit ab63110

Please sign in to comment.