Skip to content

Commit

Permalink
Merge pull request ana-rchy#6 from ana-rchy/dev
Browse files Browse the repository at this point in the history
basic easter egg reacts implementation, typo fix
  • Loading branch information
ana-rchy authored May 29, 2024
2 parents 97acd17 + fcf804b commit b19f191
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 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
2 changes: 1 addition & 1 deletion src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ResponseResults {

pub async fn get_sunset_time() -> Result<time::OffsetDateTime, reqwest::Error> {
const DUBLIN_COORDS: (&str, &str) = ("53.345727", "-6.269727");
const TIMEZONE: &str = "&tzid=Europe/Dublin";
const TIMEZONE: &str = "Europe/Dublin";
let url = format!(
"http://api.sunrise-sunset.org/json?lat={}&lng={}&formatted=0&tzid={}",
DUBLIN_COORDS.0, DUBLIN_COORDS.1, TIMEZONE
Expand Down

0 comments on commit b19f191

Please sign in to comment.