Compare commits
No commits in common. "4b42966284ada9105d1132108a50497b6df93c6a" and "4416e5d175631c416e28ae8e56706dbd3da76409" have entirely different histories.
4b42966284
...
4416e5d175
@ -1,2 +0,0 @@
|
|||||||
-- Add migration script here
|
|
||||||
ALTER TABLE reminders ADD COLUMN `thread_id` BIGINT DEFAULT NULL;
|
|
15
src/hooks.rs
15
src/hooks.rs
@ -53,22 +53,19 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
|||||||
.member_permissions(&ctx.discord(), user_id)
|
.member_permissions(&ctx.discord(), user_id)
|
||||||
.await
|
.await
|
||||||
.map_or(false, |p| p.manage_webhooks());
|
.map_or(false, |p| p.manage_webhooks());
|
||||||
|
|
||||||
let (view_channel, send_messages, embed_links) = ctx
|
let (view_channel, send_messages, embed_links) = ctx
|
||||||
.channel_id()
|
.channel_id()
|
||||||
.to_channel(&ctx.discord())
|
.to_channel_cached(&ctx.discord())
|
||||||
.await
|
|
||||||
.ok()
|
|
||||||
.and_then(|c| {
|
.and_then(|c| {
|
||||||
if let Channel::Guild(channel) = c {
|
if let Channel::Guild(channel) = c {
|
||||||
let perms = channel.permissions_for_user(&ctx.discord(), user_id).ok()?;
|
channel.permissions_for_user(&ctx.discord(), user_id).ok()
|
||||||
|
|
||||||
Some((perms.view_channel(), perms.send_messages(), perms.embed_links()))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
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 {
|
if manage_webhooks && send_messages && embed_links {
|
||||||
true
|
true
|
||||||
@ -84,8 +81,8 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
|||||||
{} **Manage Webhooks**",
|
{} **Manage Webhooks**",
|
||||||
if view_channel { "✅" } else { "❌" },
|
if view_channel { "✅" } else { "❌" },
|
||||||
if send_messages { "✅" } else { "❌" },
|
if send_messages { "✅" } else { "❌" },
|
||||||
if embed_links { "✅" } else { "❌" },
|
|
||||||
if manage_webhooks { "✅" } else { "❌" },
|
if manage_webhooks { "✅" } else { "❌" },
|
||||||
|
if embed_links { "✅" } else { "❌" },
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -90,8 +90,6 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
|
|||||||
|
|
||||||
if Path::new("/etc/reminder-rs/config.env").exists() {
|
if Path::new("/etc/reminder-rs/config.env").exists() {
|
||||||
dotenv::from_path("/etc/reminder-rs/config.env")?;
|
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");
|
let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");
|
||||||
|
@ -5,7 +5,7 @@ pub mod timer;
|
|||||||
pub mod user_data;
|
pub mod user_data;
|
||||||
|
|
||||||
use chrono_tz::Tz;
|
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::{
|
use crate::{
|
||||||
models::{channel_data::ChannelData, user_data::UserData},
|
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>> {
|
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 channel = self.channel_id().to_channel_cached(&self.discord()).unwrap();
|
||||||
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(),
|
|
||||||
};
|
|
||||||
|
|
||||||
ChannelData::from_channel(&channel, &self.data().database).await
|
ChannelData::from_channel(&channel, &self.data().database).await
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ use poise::serenity_prelude::{
|
|||||||
id::{ChannelId, GuildId, UserId},
|
id::{ChannelId, GuildId, UserId},
|
||||||
webhook::Webhook,
|
webhook::Webhook,
|
||||||
},
|
},
|
||||||
ChannelType, Result as SerenityResult,
|
Result as SerenityResult,
|
||||||
};
|
};
|
||||||
use sqlx::MySqlPool;
|
use sqlx::MySqlPool;
|
||||||
|
|
||||||
@ -51,7 +51,6 @@ pub struct ReminderBuilder {
|
|||||||
pool: MySqlPool,
|
pool: MySqlPool,
|
||||||
uid: String,
|
uid: String,
|
||||||
channel: u32,
|
channel: u32,
|
||||||
thread_id: Option<u64>,
|
|
||||||
utc_time: NaiveDateTime,
|
utc_time: NaiveDateTime,
|
||||||
timezone: String,
|
timezone: String,
|
||||||
interval_seconds: Option<i64>,
|
interval_seconds: Option<i64>,
|
||||||
@ -227,7 +226,6 @@ impl<'a> MultiReminderBuilder<'a> {
|
|||||||
errors.insert(ReminderError::LongInterval);
|
errors.insert(ReminderError::LongInterval);
|
||||||
} else {
|
} else {
|
||||||
for scope in self.scopes {
|
for scope in self.scopes {
|
||||||
let thread_id = None;
|
|
||||||
let db_channel_id = match scope {
|
let db_channel_id = match scope {
|
||||||
ReminderScope::User(user_id) => {
|
ReminderScope::User(user_id) => {
|
||||||
if let Ok(user) = UserId(user_id).to_user(&self.ctx.discord()).await {
|
if let Ok(user) = UserId(user_id).to_user(&self.ctx.discord()).await {
|
||||||
@ -260,29 +258,14 @@ impl<'a> MultiReminderBuilder<'a> {
|
|||||||
let channel =
|
let channel =
|
||||||
ChannelId(channel_id).to_channel(&self.ctx.discord()).await.unwrap();
|
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 {
|
if Some(guild_channel.guild_id) != self.guild_id {
|
||||||
Err(ReminderError::InvalidTag)
|
Err(ReminderError::InvalidTag)
|
||||||
} else {
|
} else {
|
||||||
let mut channel_data = if guild_channel.kind
|
let mut channel_data =
|
||||||
== 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)
|
ChannelData::from_channel(&channel, &self.ctx.data().database)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap();
|
||||||
};
|
|
||||||
|
|
||||||
if channel_data.webhook_id.is_none()
|
if channel_data.webhook_id.is_none()
|
||||||
|| channel_data.webhook_token.is_none()
|
|| channel_data.webhook_token.is_none()
|
||||||
@ -324,7 +307,6 @@ impl<'a> MultiReminderBuilder<'a> {
|
|||||||
pool: self.ctx.data().database.clone(),
|
pool: self.ctx.data().database.clone(),
|
||||||
uid: generate_uid(),
|
uid: generate_uid(),
|
||||||
channel: c,
|
channel: c,
|
||||||
thread_id,
|
|
||||||
utc_time: self.utc_time,
|
utc_time: self.utc_time,
|
||||||
timezone: self.timezone.to_string(),
|
timezone: self.timezone.to_string(),
|
||||||
interval_seconds: self.interval.map(|i| i.sec as i64),
|
interval_seconds: self.interval.map(|i| i.sec as i64),
|
||||||
|
Loading…
Reference in New Issue
Block a user