diff --git a/src/handlers/event/eta.rs b/src/handlers/event/eta.rs index b1c2d72..f818c2e 100644 --- a/src/handlers/event/eta.rs +++ b/src/handlers/event/eta.rs @@ -28,7 +28,10 @@ const ETA_MESSAGES: [&str; 16] = [ pub async fn handle(ctx: &Context, message: &Message) -> Result<()> { if !ETA_REGEX.is_match(&message.content) { - trace!("The message '{}' (probably) doesn't say ETA", message.content); + trace!( + "The message '{}' (probably) doesn't say ETA", + message.content + ); return Ok(()); } diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index 2fd32b0..83cb7bf 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -15,7 +15,7 @@ mod support_onboard; pub async fn handle( ctx: &Context, event: &FullEvent, - _: FrameworkContext<'_, Data, Report>, + framework: FrameworkContext<'_, Data, Report>, data: &Data, ) -> Result<()> { match event { @@ -57,7 +57,7 @@ pub async fn handle( } FullEvent::ThreadCreate { thread } => { - support_onboard::handle(ctx, thread).await?; + support_onboard::handle(ctx, thread, framework).await?; } _ => {} diff --git a/src/handlers/event/support_onboard.rs b/src/handlers/event/support_onboard.rs index ed170e1..f3aa6b1 100644 --- a/src/handlers/event/support_onboard.rs +++ b/src/handlers/event/support_onboard.rs @@ -1,15 +1,39 @@ -use eyre::{eyre, OptionExt, Result}; +use crate::Data; + +use eyre::{eyre, Context as _, OptionExt, Report, Result}; use log::{debug, trace}; use poise::serenity_prelude::{ ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel, }; +use poise::FrameworkContext; -pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> { +pub async fn handle( + ctx: &Context, + thread: &GuildChannel, + framework: FrameworkContext<'_, Data, Report>, +) -> Result<()> { if thread.kind != ChannelType::PublicThread { trace!("Not doing support onboard in non-public thread channel"); return Ok(()); } + // TODO @getchoo: it seems like we can get multiple ThreadCreate events + // should probably figure out a better way to not repeat ourselves here + if thread + .members(ctx) + .wrap_err_with(|| { + format!( + "Couldn't fetch members from thread {}! Not sending a support onboard message.", + thread.id + ) + })? + .iter() + .any(|member| member.user.id == framework.bot_id) + { + debug!("Not sending support onboard message...I think i've been here before :p"); + return Ok(()); + } + if thread .parent_id .ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?