Moved stuff around since threads are ridiculous
This commit is contained in:
@ -9,7 +9,7 @@ use poise::serenity_prelude::{
|
||||
id::{ChannelId, GuildId, UserId},
|
||||
webhook::Webhook,
|
||||
},
|
||||
Result as SerenityResult,
|
||||
ChannelType, Result as SerenityResult,
|
||||
};
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
@ -36,7 +36,6 @@ async fn create_webhook(
|
||||
pub enum ReminderScope {
|
||||
User(u64),
|
||||
Channel(u64),
|
||||
Thread(u64),
|
||||
}
|
||||
|
||||
impl ReminderScope {
|
||||
@ -44,7 +43,6 @@ impl ReminderScope {
|
||||
match self {
|
||||
Self::User(id) => format!("<@{}>", id),
|
||||
Self::Channel(id) => format!("<#{}>", id),
|
||||
Self::Thread(id) => format!("<#{}>", id),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,6 +227,7 @@ impl<'a> MultiReminderBuilder<'a> {
|
||||
errors.insert(ReminderError::LongInterval);
|
||||
} else {
|
||||
for scope in self.scopes {
|
||||
let thread_id = None;
|
||||
let db_channel_id = match scope {
|
||||
ReminderScope::User(user_id) => {
|
||||
if let Ok(user) = UserId(user_id).to_user(&self.ctx.discord()).await {
|
||||
@ -261,14 +260,29 @@ impl<'a> MultiReminderBuilder<'a> {
|
||||
let channel =
|
||||
ChannelId(channel_id).to_channel(&self.ctx.discord()).await.unwrap();
|
||||
|
||||
if let Some(guild_channel) = channel.clone().guild() {
|
||||
if let Some(mut guild_channel) = channel.clone().guild() {
|
||||
if Some(guild_channel.guild_id) != self.guild_id {
|
||||
Err(ReminderError::InvalidTag)
|
||||
} else {
|
||||
let mut channel_data =
|
||||
ChannelData::from_channel(&channel, &self.ctx.data().database)
|
||||
let mut channel_data = if guild_channel.kind
|
||||
== ChannelType::PublicThread
|
||||
{
|
||||
// fixme jesus christ
|
||||
let parent = guild_channel
|
||||
.parent_id
|
||||
.unwrap()
|
||||
.to_channel(&self.ctx.discord())
|
||||
.await
|
||||
.unwrap();
|
||||
guild_channel = parent.clone().guild().unwrap();
|
||||
ChannelData::from_channel(&parent, &self.ctx.data().database)
|
||||
.await
|
||||
.unwrap()
|
||||
} else {
|
||||
ChannelData::from_channel(&channel, &self.ctx.data().database)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
if channel_data.webhook_id.is_none()
|
||||
|| channel_data.webhook_token.is_none()
|
||||
@ -302,66 +316,6 @@ impl<'a> MultiReminderBuilder<'a> {
|
||||
Err(ReminderError::InvalidTag)
|
||||
}
|
||||
}
|
||||
ReminderScope::Thread(thread_id) => {
|
||||
let thread =
|
||||
ChannelId(thread_id).to_channel(&self.ctx.discord()).await.unwrap();
|
||||
|
||||
if let Some(guild_channel) = thread.guild() {
|
||||
if Some(guild_channel.guild_id) != self.guild_id {
|
||||
Err(ReminderError::InvalidTag)
|
||||
} else {
|
||||
match guild_channel.parent_id {
|
||||
Some(parent_id) => {
|
||||
let channel = parent_id
|
||||
.to_channel(&self.ctx.discord())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut channel_data = ChannelData::from_channel(
|
||||
&channel,
|
||||
&self.ctx.data().database,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if channel_data.webhook_id.is_none()
|
||||
|| channel_data.webhook_token.is_none()
|
||||
{
|
||||
match create_webhook(
|
||||
&self.ctx.discord(),
|
||||
channel.guild().unwrap(),
|
||||
"Reminder",
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(webhook) => {
|
||||
channel_data.webhook_id =
|
||||
Some(webhook.id.as_u64().to_owned());
|
||||
channel_data.webhook_token = webhook.token;
|
||||
|
||||
channel_data
|
||||
.commit_changes(&self.ctx.data().database)
|
||||
.await;
|
||||
|
||||
Ok(channel_data.id)
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
Err(ReminderError::DiscordError(e.to_string()))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Ok(channel_data.id)
|
||||
}
|
||||
}
|
||||
|
||||
None => Err(ReminderError::InvalidTag),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(ReminderError::InvalidTag)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match db_channel_id {
|
||||
@ -370,7 +324,7 @@ impl<'a> MultiReminderBuilder<'a> {
|
||||
pool: self.ctx.data().database.clone(),
|
||||
uid: generate_uid(),
|
||||
channel: c,
|
||||
thread_id: None,
|
||||
thread_id,
|
||||
utc_time: self.utc_time,
|
||||
timezone: self.timezone.to_string(),
|
||||
interval_seconds: self.interval.map(|i| i.sec as i64),
|
||||
|
Reference in New Issue
Block a user