support_onboard: check if bot has already joined thread
This commit is contained in:
parent
915ef54dc3
commit
cd1e3220c7
3 changed files with 32 additions and 5 deletions
|
@ -28,7 +28,10 @@ const ETA_MESSAGES: [&str; 16] = [
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
||||||
if !ETA_REGEX.is_match(&message.content) {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ mod support_onboard;
|
||||||
pub async fn handle(
|
pub async fn handle(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
event: &FullEvent,
|
event: &FullEvent,
|
||||||
_: FrameworkContext<'_, Data, Report>,
|
framework: FrameworkContext<'_, Data, Report>,
|
||||||
data: &Data,
|
data: &Data,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match event {
|
match event {
|
||||||
|
@ -57,7 +57,7 @@ pub async fn handle(
|
||||||
}
|
}
|
||||||
|
|
||||||
FullEvent::ThreadCreate { thread } => {
|
FullEvent::ThreadCreate { thread } => {
|
||||||
support_onboard::handle(ctx, thread).await?;
|
support_onboard::handle(ctx, thread, framework).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -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 log::{debug, trace};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel,
|
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 {
|
if thread.kind != ChannelType::PublicThread {
|
||||||
trace!("Not doing support onboard in non-public thread channel");
|
trace!("Not doing support onboard in non-public thread channel");
|
||||||
return Ok(());
|
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
|
if thread
|
||||||
.parent_id
|
.parent_id
|
||||||
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue