use serenity::async_trait; use serenity::model::channel::Reaction; use serenity::model::gateway::Ready; use serenity::prelude::{Context, EventHandler}; use crate::discord::utility::schedule_all_events; use crate::discord::{tasks, utility}; use crate::INTERESTED_EMOJI; /// Handler for Discord events pub struct Handler; #[async_trait] impl EventHandler for Handler { /// On reaction add async fn reaction_add(&self, ctx: Context, reaction: Reaction) { let config = utility::get_config(&ctx.data.read().await) .await .expect("Unable to get config"); if reaction.channel_id.0 == config.event_channel && reaction.emoji.as_data().chars().next().unwrap() == INTERESTED_EMOJI { utility::send_message_to_reaction_users( &ctx, &reaction, "Hello, you are now receiving reminders for **{event}**", ) .await; } } /// On reaction remove async fn reaction_remove(&self, ctx: Context, reaction: Reaction) { let config = utility::get_config(&ctx.data.read().await) .await .expect("Unable to get config"); if reaction.channel_id.0 == config.event_channel && reaction.emoji.as_data().chars().next().unwrap() == INTERESTED_EMOJI { utility::send_message_to_reaction_users( &ctx, &reaction, "Hello, you are no longer receiving reminders for **{event}**", ) .await; } } /// On bot ready async fn ready(&self, ctx: Context, ready: Ready) { info!("Connected to Discord as {}", ready.user.name); schedule_all_events(&ctx).await; let cleanup_ctx = ctx.clone(); tokio::spawn(async move { tasks::send_reminders_task(&ctx).await; }); tokio::spawn(async move { tasks::cleanup_task(&cleanup_ctx).await; }); info!("Setup complete.") } }