diff --git a/migrations/20260516170852_drop_columns.sql b/migrations/20260516170852_drop_columns.sql new file mode 100644 index 0000000..7c7fbee --- /dev/null +++ b/migrations/20260516170852_drop_columns.sql @@ -0,0 +1,17 @@ +SET foreign_key_checks = 0; + +-- Drop all old tables +DROP TABLE IF EXISTS users_old; +DROP TABLE IF EXISTS messages; +DROP TABLE IF EXISTS embeds; +DROP TABLE IF EXISTS embed_fields; +DROP TABLE IF EXISTS command_aliases; +DROP TABLE IF EXISTS macro; +DROP TABLE IF EXISTS roles; +DROP TABLE IF EXISTS command_restrictions; + +-- Drop columns from channels that are no longer used +ALTER TABLE channels DROP COLUMN `name`; +ALTER TABLE channels DROP COLUMN `blacklisted`; + +SET foreign_key_checks = 1; diff --git a/src/commands/look.rs b/src/commands/look.rs index 1363967..ab062a5 100644 --- a/src/commands/look.rs +++ b/src/commands/look.rs @@ -56,7 +56,7 @@ impl Recordable for Options { }), }; - let channel_id = if let Some(channel) = ctx.channel_id().to_channel_cached(&ctx.cache()) { + let channel_id = if let Some(channel) = ctx.cache().guild_channel(ctx.channel_id()) { if Some(channel.guild_id) == ctx.guild_id() { flags.channel_id.unwrap_or_else(|| ctx.channel_id()) } else { @@ -67,7 +67,7 @@ impl Recordable for Options { }; let channel_name = - channel_id.to_channel_cached(&ctx.cache()).map(|channel| channel.name.clone()); + ctx.cache().guild_channel(channel_id).map(|channel| channel.name.clone()); let reminders = Reminder::from_channel(&ctx.data().database, channel_id, &flags).await; diff --git a/src/component_models/mod.rs b/src/component_models/mod.rs index a1f1094..a737794 100644 --- a/src/component_models/mod.rs +++ b/src/component_models/mod.rs @@ -63,7 +63,7 @@ impl ComponentDataModel { let flags = pager.flags; let channel_id = { - let channel_opt = component.channel_id.to_channel_cached(&ctx.cache); + let channel_opt = ctx.cache.guild_channel(component.channel_id); if let Some(channel) = channel_opt { if Some(channel.guild_id) == component.guild_id { @@ -85,7 +85,7 @@ impl ComponentDataModel { .div_ceil(EMBED_DESCRIPTION_MAX_LENGTH); let channel_name = - channel_id.to_channel_cached(&ctx.cache).map(|channel| channel.name.clone()); + ctx.cache.guild_channel(channel_id).map(|channel| channel.name.clone()); let next_page = pager.next_page(pages); diff --git a/src/hooks.rs b/src/hooks.rs index 2372485..330fe3b 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -99,9 +99,8 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool { match ctx.guild().map(|g| g.to_owned()) { Some(guild) => { let manage_webhooks = guild - .member(&ctx, user_id) - .await - .map_or(false, |m| m.permissions(&ctx).map_or(false, |p| p.manage_webhooks())); + .member_permissions_in(&ctx, ctx.channel_id(), user_id) + .map_or(false, |p| p.manage_webhooks()); if let Some(permissions) = app_permissions { return if permissions.send_messages() diff --git a/src/models/channel_data.rs b/src/models/channel_data.rs index 0122b80..107c4b6 100644 --- a/src/models/channel_data.rs +++ b/src/models/channel_data.rs @@ -8,9 +8,7 @@ use crate::{consts::DEFAULT_AVATAR, Error}; pub struct ChannelData { pub id: u32, pub channel: u64, - pub name: Option, pub nudge: i16, - pub blacklisted: bool, pub webhook_id: Option, pub webhook_token: Option, pub paused: bool, @@ -27,7 +25,7 @@ impl ChannelData { if let Ok(c) = sqlx::query_as_unchecked!( Self, " - SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused, + SELECT id, channel, nudge, webhook_id, webhook_token, paused, paused_until FROM channels WHERE channel = ? @@ -56,7 +54,7 @@ impl ChannelData { Ok(sqlx::query_as_unchecked!( Self, " - SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until + SELECT id, channel, nudge, webhook_id, webhook_token, paused, paused_until FROM channels WHERE channel = ? ", @@ -72,18 +70,14 @@ impl ChannelData { " UPDATE channels SET - name = ?, nudge = ?, - blacklisted = ?, webhook_id = ?, webhook_token = ?, paused = ?, paused_until = ? WHERE id = ? ", - self.name, self.nudge, - self.blacklisted, self.webhook_id, self.webhook_token, self.paused, diff --git a/src/web/ip_blocking.rs b/src/web/ip_blocking.rs index dad9ab8..3a23e1a 100644 --- a/src/web/ip_blocking.rs +++ b/src/web/ip_blocking.rs @@ -42,7 +42,7 @@ impl IpBlocking { fn contains>(&self, ip: I) -> bool { let ip: u32 = ip.into(); - let mut prev_index = self.upper_ips.len() - 1; + let _prev_index = self.upper_ips.len() - 1; let mut index = self.upper_ips.len() / 2; loop { if self.upper_ips[index] <= ip && self.lower_ips[index] >= ip { diff --git a/src/web/mod.rs b/src/web/mod.rs index b9bf0be..420b89b 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -63,7 +63,6 @@ use log::{error, info, warn}; use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl}; use poise::serenity_prelude::{ client::Context, - http::CacheHttp, model::id::{GuildId, UserId}, }; use rocket::{ @@ -76,13 +75,9 @@ use rocket::{ }; use rocket_dyn_templates::Template; use sqlx::{MySql, Pool}; -use std::net::Ipv4Addr; use std::{env, path::Path}; -use crate::web::{ - consts::{CNC_GUILD, DISCORD_OAUTH_AUTHORIZE, DISCORD_OAUTH_TOKEN, SUBSCRIPTION_ROLES}, - fairings::metrics::MetricProducer, -}; +use crate::web::fairings::metrics::MetricProducer; type Database = MySql; @@ -255,7 +250,11 @@ pub async fn check_authorization( match guild_id.member(ctx, UserId::new(user_id)).await { Ok(member) => { - let permissions_res = member.permissions(ctx); + let permissions_res = ctx + .cache + .guild(guild_id) + .map(|g| g.member_permissions_in(ctx, UserId::new(user_id))) + .unwrap_or(Err(serenity::all::Error::Other("Guild not in cache"))); match permissions_res { Err(_) => { diff --git a/src/web/routes/dashboard/api/guild/mod.rs b/src/web/routes/dashboard/api/guild/mod.rs index f77437b..e591b85 100644 --- a/src/web/routes/dashboard/api/guild/mod.rs +++ b/src/web/routes/dashboard/api/guild/mod.rs @@ -5,8 +5,6 @@ mod roles; mod templates; pub mod todos; -use std::env; - use crate::utils::check_subscription; use crate::web::guards::transaction::Transaction; use crate::web::{check_authorization, routes::JsonResult}; @@ -16,10 +14,7 @@ pub use reminders::*; use rocket::{get, http::CookieJar, serde::json::json, State}; pub use roles::get_guild_roles; use serenity::all::UserId; -use serenity::{ - client::Context, - model::id::{GuildId, RoleId}, -}; +use serenity::{client::Context, model::id::GuildId}; pub use templates::*; #[get("/api/guild/")] diff --git a/src/web/routes/dashboard/api/guild/reminders.rs b/src/web/routes/dashboard/api/guild/reminders.rs index ac1792e..239abe7 100644 --- a/src/web/routes/dashboard/api/guild/reminders.rs +++ b/src/web/routes/dashboard/api/guild/reminders.rs @@ -267,8 +267,9 @@ pub async fn edit_reminder( } if reminder.channel > 0 { - let channel_guild = ChannelId::new(reminder.channel) - .to_channel_cached(&ctx.cache) + let channel_guild = ctx + .cache + .guild_channel(ChannelId::new(reminder.channel)) .map(|channel| channel.guild_id); match channel_guild { Some(channel_guild) => { diff --git a/src/web/routes/dashboard/export/reminder_templates.rs b/src/web/routes/dashboard/export/reminder_templates.rs index 56d0d10..e8305f8 100644 --- a/src/web/routes/dashboard/export/reminder_templates.rs +++ b/src/web/routes/dashboard/export/reminder_templates.rs @@ -3,13 +3,10 @@ use crate::web::{ check_authorization, guards::transaction::Transaction, routes::{ - dashboard::{ - create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv, - }, + dashboard::{ImportBody, ReminderTemplateCsv}, JsonResult, }, }; -use crate::Database; use base64::{prelude::BASE64_STANDARD, Engine}; use csv::{QuoteStyle, WriterBuilder}; use log::warn; @@ -20,10 +17,7 @@ use rocket::{ serde::json::{json, Json}, State, }; -use serenity::{ - client::Context, - model::id::{ChannelId, GuildId, UserId}, -}; +use serenity::{client::Context, model::id::GuildId}; use sqlx::{MySql, Pool}; #[get("/api/guild//export/reminder_templates")] diff --git a/src/web/routes/dashboard/export/reminders.rs b/src/web/routes/dashboard/export/reminders.rs index 7576fb8..680caf1 100644 --- a/src/web/routes/dashboard/export/reminders.rs +++ b/src/web/routes/dashboard/export/reminders.rs @@ -2,9 +2,7 @@ use crate::web::{ check_authorization, guards::transaction::Transaction, routes::{ - dashboard::{ - create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv, - }, + dashboard::{create_reminder, CreateReminder, ImportBody, ReminderCsv}, JsonResult, }, }; @@ -21,7 +19,7 @@ use rocket::{ }; use serenity::{ client::Context, - model::id::{ChannelId, GuildId, UserId}, + model::id::{GuildId, UserId}, }; use sqlx::{MySql, Pool}; diff --git a/src/web/routes/dashboard/export/todos.rs b/src/web/routes/dashboard/export/todos.rs index d291a56..8560090 100644 --- a/src/web/routes/dashboard/export/todos.rs +++ b/src/web/routes/dashboard/export/todos.rs @@ -1,14 +1,10 @@ use crate::web::{ check_authorization, - guards::transaction::Transaction, routes::{ - dashboard::{ - create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv, - }, + dashboard::{ImportBody, TodoCsv}, JsonResult, }, }; -use crate::Database; use base64::{prelude::BASE64_STANDARD, Engine}; use csv::{QuoteStyle, WriterBuilder}; use log::warn; @@ -21,7 +17,7 @@ use rocket::{ }; use serenity::{ client::Context, - model::id::{ChannelId, GuildId, UserId}, + model::id::{ChannelId, GuildId}, }; use sqlx::{MySql, Pool}; diff --git a/src/web/routes/dashboard/mod.rs b/src/web/routes/dashboard/mod.rs index 1ee5c74..54f9c86 100644 --- a/src/web/routes/dashboard/mod.rs +++ b/src/web/routes/dashboard/mod.rs @@ -8,7 +8,6 @@ use rocket::{ fs::NamedFile, get, http::CookieJar, response::Redirect, serde::json::json, Responder, }; use rocket_dyn_templates::Template; -use secrecy::ExposeSecret; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serenity::http::HttpError; use serenity::{