revanced-discord-bot/src/events/thread_create.rs
2022-08-20 15:45:02 +02:00

37 lines
996 B
Rust

use tracing::{debug, error};
use super::*;
use crate::utils::bot::get_data_lock;
pub async fn thread_create(ctx: &serenity::Context, thread: &serenity::GuildChannel) {
if thread.member.is_some() {
debug!("Thread was joined. Block dispatch.");
return;
}
debug!("Thread created: {:?}", thread);
let data_lock = get_data_lock(ctx).await;
let configuration_lock = data_lock.read().await;
let thread_introductions = &configuration_lock
.configuration
.read()
.await
.thread_introductions;
if let Some(introducer) = thread_introductions.iter().find(|introducer| {
introducer
.channels
.iter()
.any(|channel_id| *channel_id == thread.parent_id.unwrap().0)
}) {
if let Err(why) = thread
.say(&ctx.http, &introducer.response.message.as_ref().unwrap())
.await
{
error!("Error sending message: {:?}", why);
}
}
}