Moved stuff around since threads are ridiculous
This commit is contained in:
parent
523ab7f03a
commit
4b42966284
@ -5,8 +5,7 @@ use chrono_tz::Tz;
|
||||
use num_integer::Integer;
|
||||
use poise::{
|
||||
serenity_prelude::{
|
||||
builder::CreateEmbed, component::ButtonStyle, model::channel::Channel, ChannelType,
|
||||
ReactionType,
|
||||
builder::CreateEmbed, component::ButtonStyle, model::channel::Channel, ReactionType,
|
||||
},
|
||||
CreateReply, Modal,
|
||||
};
|
||||
@ -665,18 +664,10 @@ async fn create_reminder(
|
||||
let list = channels.map(|arg| parse_mention_list(&arg)).unwrap_or_default();
|
||||
|
||||
if list.is_empty() {
|
||||
let channel = ctx.channel_id().to_channel(&ctx.discord()).await?;
|
||||
|
||||
match channel.guild() {
|
||||
Some(guild_channel) => {
|
||||
if guild_channel.kind == ChannelType::PublicThread {
|
||||
vec![ReminderScope::Thread(ctx.channel_id().0)]
|
||||
} else {
|
||||
vec![ReminderScope::Channel(ctx.channel_id().0)]
|
||||
}
|
||||
}
|
||||
|
||||
None => vec![ReminderScope::User(ctx.author().id.0)],
|
||||
if ctx.guild_id().is_some() {
|
||||
vec![ReminderScope::Channel(ctx.channel_id().0)]
|
||||
} else {
|
||||
vec![ReminderScope::User(ctx.author().id.0)]
|
||||
}
|
||||
} else {
|
||||
list
|
||||
@ -824,7 +815,6 @@ fn create_response(
|
||||
embed
|
||||
}
|
||||
|
||||
// TODO process threads here
|
||||
fn parse_mention_list(mentions: &str) -> Vec<ReminderScope> {
|
||||
REGEX_CHANNEL_USER
|
||||
.captures_iter(mentions)
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user