Compare commits

..

No commits in common. "4b42966284ada9105d1132108a50497b6df93c6a" and "4416e5d175631c416e28ae8e56706dbd3da76409" have entirely different histories.

5 changed files with 12 additions and 50 deletions

View File

@ -1,2 +0,0 @@
-- Add migration script here
ALTER TABLE reminders ADD COLUMN `thread_id` BIGINT DEFAULT NULL;

View File

@ -53,22 +53,19 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
.member_permissions(&ctx.discord(), user_id)
.await
.map_or(false, |p| p.manage_webhooks());
let (view_channel, send_messages, embed_links) = ctx
.channel_id()
.to_channel(&ctx.discord())
.await
.ok()
.to_channel_cached(&ctx.discord())
.and_then(|c| {
if let Channel::Guild(channel) = c {
let perms = channel.permissions_for_user(&ctx.discord(), user_id).ok()?;
Some((perms.view_channel(), perms.send_messages(), perms.embed_links()))
channel.permissions_for_user(&ctx.discord(), user_id).ok()
} else {
None
}
})
.unwrap_or((false, false, false));
.map_or((false, false, false), |p| {
(p.view_channel(), p.send_messages(), p.embed_links())
});
if manage_webhooks && send_messages && embed_links {
true
@ -84,8 +81,8 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
{} **Manage Webhooks**",
if view_channel { "" } else { "" },
if send_messages { "" } else { "" },
if embed_links { "" } else { "" },
if manage_webhooks { "" } else { "" },
if embed_links { "" } else { "" },
))
})
.await;

View File

@ -90,8 +90,6 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
if Path::new("/etc/reminder-rs/config.env").exists() {
dotenv::from_path("/etc/reminder-rs/config.env")?;
} else {
dotenv::from_path(".env")?;
}
let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");

View File

@ -5,7 +5,7 @@ pub mod timer;
pub mod user_data;
use chrono_tz::Tz;
use poise::serenity_prelude::{async_trait, model::id::UserId, ChannelType};
use poise::serenity_prelude::{async_trait, model::id::UserId};
use crate::{
models::{channel_data::ChannelData, user_data::UserData},
@ -43,20 +43,7 @@ impl CtxData for Context<'_> {
}
async fn channel_data(&self) -> Result<ChannelData, Box<dyn std::error::Error + Sync + Send>> {
// If we're in a thread, get the parent channel.
let recv_channel = self.channel_id().to_channel(&self.discord()).await?;
let channel = match recv_channel.guild() {
Some(guild_channel) => {
if guild_channel.kind == ChannelType::PublicThread {
guild_channel.parent_id.unwrap().to_channel_cached(&self.discord()).unwrap()
} else {
self.channel_id().to_channel_cached(&self.discord()).unwrap()
}
}
None => self.channel_id().to_channel_cached(&self.discord()).unwrap(),
};
let channel = self.channel_id().to_channel_cached(&self.discord()).unwrap();
ChannelData::from_channel(&channel, &self.data().database).await
}

View File

@ -9,7 +9,7 @@ use poise::serenity_prelude::{
id::{ChannelId, GuildId, UserId},
webhook::Webhook,
},
ChannelType, Result as SerenityResult,
Result as SerenityResult,
};
use sqlx::MySqlPool;
@ -51,7 +51,6 @@ pub struct ReminderBuilder {
pool: MySqlPool,
uid: String,
channel: u32,
thread_id: Option<u64>,
utc_time: NaiveDateTime,
timezone: String,
interval_seconds: Option<i64>,
@ -227,7 +226,6 @@ 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 {
@ -260,29 +258,14 @@ impl<'a> MultiReminderBuilder<'a> {
let channel =
ChannelId(channel_id).to_channel(&self.ctx.discord()).await.unwrap();
if let Some(mut guild_channel) = channel.clone().guild() {
if let Some(guild_channel) = channel.clone().guild() {
if Some(guild_channel.guild_id) != self.guild_id {
Err(ReminderError::InvalidTag)
} else {
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 {
let mut channel_data =
ChannelData::from_channel(&channel, &self.ctx.data().database)
.await
.unwrap()
};
.unwrap();
if channel_data.webhook_id.is_none()
|| channel_data.webhook_token.is_none()
@ -324,7 +307,6 @@ impl<'a> MultiReminderBuilder<'a> {
pool: self.ctx.data().database.clone(),
uid: generate_uid(),
channel: c,
thread_id,
utc_time: self.utc_time,
timezone: self.timezone.to_string(),
interval_seconds: self.interval.map(|i| i.sec as i64),