From 604a81fb449e1f64d20a58c3f14f1e2b6798bb2f Mon Sep 17 00:00:00 2001 From: seth Date: Mon, 4 Dec 2023 06:04:38 -0500 Subject: [PATCH] feat: reintroduce support onboarding Signed-off-by: seth --- src/handlers/event/mod.rs | 3 ++ src/handlers/event/support_onboard.rs | 43 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/handlers/event/support_onboard.rs diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index e5379ae..ad63d66 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -6,6 +6,7 @@ use poise::{Event, FrameworkContext}; mod delete; mod eta; +mod support_onboard; pub async fn handle( ctx: &Context, @@ -30,6 +31,8 @@ pub async fn handle( Event::ReactionAdd { add_reaction } => delete::handle(ctx, add_reaction).await?, + Event::ThreadCreate { thread } => support_onboard::handle(ctx, thread).await?, + _ => {} } diff --git a/src/handlers/event/support_onboard.rs b/src/handlers/event/support_onboard.rs new file mode 100644 index 0000000..9b6bc16 --- /dev/null +++ b/src/handlers/event/support_onboard.rs @@ -0,0 +1,43 @@ +use color_eyre::eyre::{eyre, Result}; +use log::*; +use poise::serenity_prelude::{ChannelType, Context, GuildChannel}; + +pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> { + if thread.kind != ChannelType::PublicThread { + return Ok(()); + } + + let parent_id = thread + .parent_id + .ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?; + + let parent_channel = ctx + .cache + .guild_channel(parent_id) + .ok_or_else(|| eyre!("Couldn't get GuildChannel {}!", parent_id))?; + + if parent_channel.name != "support" { + debug!("Not posting onboarding message to threads outside of support"); + return Ok(()); + } + + let owner = thread + .owner_id + .ok_or_else(|| eyre!("Couldn't get owner of thread!"))?; + + let msg = format!( + "<@{}> We've received your support ticket! {} {}", + owner, + "Please upload your logs and post the link here if possible (run `tag log` to find out how).", + "Please don't ping people for support questions, unless you have their permission." + ); + + thread + .send_message(ctx, |m| { + m.content(msg) + .allowed_mentions(|am| am.replied_user(true).users(Vec::from([owner]))) + }) + .await?; + + Ok(()) +}