Skip to content

Commit

Permalink
easter egg reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-rchy committed May 22, 2024
1 parent 2f8bb29 commit 74f426d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ pub async fn event_handler(

serenity::FullEvent::Message { new_message } => {
// early returns
const BOT_ID: u64 = 1235086289255137404;
#[allow(dead_code)]
const TESTING_CHANNEL_ID: u64 = 1235087573421133824;
const GENERAL_CHANNEL_ID: u64 = 1215048710074011692;
const BOT_ID: u64 = 1235086289255137404;

let sunset_time = *shared_data.sunset_time.lock().unwrap();
let current_time = OffsetDateTime::now_utc().to_offset(sunset_time.offset());

if !(current_time > sunset_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 @@ -81,3 +85,17 @@ pub async fn event_handler(

Ok(())
}

async fn easter_egg_reacts(ctx: &serenity::Context, message: &serenity::model::channel::Message) {
if !message.content.to_lowercase().contains("good morning") {
return;
}

let reaction = ReactionType::Custom {
animated: true,
id: EmojiId::new(1218307823549546496),
name: Some("nerdo".to_string()),
};

message.react(&ctx.http, reaction).await.unwrap();
}
3 changes: 2 additions & 1 deletion src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ pub async fn init_jobs(
client: &serenity::Client,
shared_data: &SharedData
) -> Result<(), JobSchedulerError> {
#[allow(dead_code)]
const TESTING_CHANNEL_ID: u64 = 1235087573421133824;
const GENERAL_CHANNEL_ID: u64 = 1215048710074011692;
#[allow(dead_code)] const TESTING_CHANNEL_ID: u64 = 1235087573421133824;

let http = client.http.clone();

Expand Down

0 comments on commit 74f426d

Please sign in to comment.