support_onboard: check if bot has already joined thread

This commit is contained in:
seth 2024-03-03 18:46:34 -05:00
parent 915ef54dc3
commit cd1e3220c7
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
3 changed files with 32 additions and 5 deletions

View file

@ -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))?