diff --git a/Cargo.lock b/Cargo.lock index 5730115..b2c14d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2645,9 +2645,9 @@ dependencies = [ [[package]] name = "rocket_dyn_templates" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04bfc006e547e4f72b760ab861f5943b688aed8a82c4977b5500c98f5d17dbfa" +checksum = "5bbab919c9e67df3f7ac6624a32ef897df4cd61c0969f4d66f3ced0534660d7a" dependencies = [ "normpath", "notify", diff --git a/Cargo.toml b/Cargo.toml index 4bf6fdb..3bb31f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ secrecy = "0.8.0" futures = "0.3.30" prometheus = "0.13.3" rocket = { version = "0.5.0", features = ["tls", "secrets", "json"] } -rocket_dyn_templates = { version = "0.1.0", features = ["tera"] } +rocket_dyn_templates = { version = "0.2.0", features = ["tera"] } serenity = { version = "0.12", default-features = false, features = ["builder", "cache", "client", "gateway", "http", "model", "utils", "rustls_backend"] } oauth2 = "4" csv = "1.2" diff --git a/migrations/20210603000000_initial.sql b/migrations/20210603000000_initial.sql index e1527dc..aca6864 100644 --- a/migrations/20210603000000_initial.sql +++ b/migrations/20210603000000_initial.sql @@ -136,9 +136,9 @@ CREATE TABLE reminders ( set_by INT UNSIGNED, PRIMARY KEY (id), - FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE RESTRICT, - FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE, - FOREIGN KEY (set_by) REFERENCES users(id) ON DELETE SET NULL + CONSTRAINT `reminder_message_fk` FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE RESTRICT, + CONSTRAINT `reminder_channel_fk` FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE, + CONSTRAINT `reminder_user_fk` FOREIGN KEY (set_by) REFERENCES users(id) ON DELETE SET NULL ); CREATE TRIGGER message_cleanup AFTER DELETE ON reminders @@ -157,9 +157,9 @@ CREATE TABLE todos ( value VARCHAR(2000) NOT NULL, PRIMARY KEY (id), - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL, - FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE, - FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE SET NULL + CONSTRAINT todos_ibfk_5 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL, + CONSTRAINT todos_ibfk_4 FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE, + CONSTRAINT todos_ibfk_3 FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE SET NULL ); CREATE TABLE command_restrictions ( diff --git a/migrations/20210623000000_reminder_message_embed.sql b/migrations/20210623000000_reminder_message_embed.sql index e6b83cb..3293f36 100644 --- a/migrations/20210623000000_reminder_message_embed.sql +++ b/migrations/20210623000000_reminder_message_embed.sql @@ -46,7 +46,7 @@ CREATE TABLE reminders_new ( PRIMARY KEY (id), FOREIGN KEY (`channel_id`) REFERENCES channels (`id`) ON DELETE CASCADE, - FOREIGN KEY (`set_by`) REFERENCES users (`id`) ON DELETE SET NULL + CONSTRAINT `reminders_ibfk_2` FOREIGN KEY (`set_by`) REFERENCES `users` (`id`) ON DELETE SET NULL # disallow having a reminder as restartable if it has no interval -- , CONSTRAINT restartable_interval_mutex CHECK (`restartable` = 0 OR `interval` IS NULL) diff --git a/migrations/20240630150936_dashboard_preferences.sql b/migrations/20240630150936_dashboard_preferences.sql index 2069663..4e33e69 100644 --- a/migrations/20240630150936_dashboard_preferences.sql +++ b/migrations/20240630150936_dashboard_preferences.sql @@ -1,3 +1,7 @@ +-- Tables no longer needed as old dashboard is decomm. +DROP TABLE guild_users; +DROP TABLE events; + ALTER TABLE users ADD COLUMN `reset_inputs_on_create` BOOLEAN NOT NULL DEFAULT 0; ALTER TABLE users ADD COLUMN `use_browser_timezone` BOOLEAN NOT NULL DEFAULT 1; ALTER TABLE users ADD COLUMN `dashboard_color_scheme` ENUM('system', 'light', 'dark') NOT NULL DEFAULT 'system'; @@ -7,4 +11,14 @@ ALTER TABLE users DROP COLUMN `patreon`; ALTER TABLE users DROP COLUMN `name`; ALTER TABLE users DROP PRIMARY KEY, ADD PRIMARY KEY (`user`); + +ALTER TABLE todos DROP CONSTRAINT todos_ibfk_5, MODIFY COLUMN user_id BIGINT UNSIGNED; +UPDATE todos SET user_id = (SELECT user FROM users WHERE id = user_id); +ALTER TABLE todos ADD CONSTRAINT todos_user_fk FOREIGN KEY (user_id) REFERENCES users(user); + +ALTER TABLE reminders DROP CONSTRAINT reminders_ibfk_2, MODIFY COLUMN set_by BIGINT UNSIGNED; +UPDATE reminders SET set_by = (SELECT user FROM users WHERE id = set_by); +ALTER TABLE reminders ADD CONSTRAINT reminder_user_fk FOREIGN KEY (set_by) REFERENCES users(user); + +ALTER TABLE users DROP COLUMN `id`; ALTER TABLE users RENAME COLUMN `user` TO `id`; diff --git a/src/event_handlers.rs b/src/event_handlers.rs index 80cc258..4a50e95 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -1,6 +1,6 @@ use poise::{ serenity_prelude as serenity, - serenity_prelude::{ActivityData, CreateEmbed, CreateMessage, FullEvent}, + serenity_prelude::{CreateEmbed, CreateMessage, FullEvent}, }; use crate::{ diff --git a/src/hooks.rs b/src/hooks.rs index b8c2a2b..d122a0b 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -1,4 +1,4 @@ -use poise::{serenity_prelude::model::channel::Channel, CommandInteractionType, CreateReply}; +use poise::{CommandInteractionType, CreateReply}; use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error}; diff --git a/src/web/routes/dashboard/api/guild/roles.rs b/src/web/routes/dashboard/api/guild/roles.rs index bf0205b..51e9a66 100644 --- a/src/web/routes/dashboard/api/guild/roles.rs +++ b/src/web/routes/dashboard/api/guild/roles.rs @@ -16,17 +16,15 @@ pub async fn get_guild_roles(id: u64, cookies: &CookieJar<'_>, ctx: &State>() + }); match roles_res { - Some(roles) => { - let roles = roles - .iter() - .map(|(_, r)| RoleInfo { id: r.id.to_string(), name: r.name.to_string() }) - .collect::>(); - - Ok(json!(roles)) - } + Some(roles) => Ok(json!(roles)), None => { warn!("Could not fetch roles from {}", id); diff --git a/src/web/routes/dashboard/api/user/mod.rs b/src/web/routes/dashboard/api/user/mod.rs index 388c434..749711d 100644 --- a/src/web/routes/dashboard/api/user/mod.rs +++ b/src/web/routes/dashboard/api/user/mod.rs @@ -137,7 +137,7 @@ pub async fn update_user_info( } if let Some(dashboard_color_scheme) = &preferences.dashboard_color_scheme { - if vec!["system", "light", "dark"].contains(dashboard_color_scheme) { + if vec!["system", "light", "dark"].contains(&dashboard_color_scheme.as_str()) { let _ = sqlx::query!( " UPDATE users diff --git a/src/web/routes/dashboard/mod.rs b/src/web/routes/dashboard/mod.rs index c170db5..08c31e5 100644 --- a/src/web/routes/dashboard/mod.rs +++ b/src/web/routes/dashboard/mod.rs @@ -593,18 +593,11 @@ pub(crate) async fn create_reminder( } fn check_channel_matches_guild(ctx: &Context, channel_id: ChannelId, guild_id: GuildId) -> bool { - // validate channel - let channel = channel_id.to_channel_cached(&ctx.cache); - let channel_exists = channel.is_some(); + return match ctx.cache.guild(guild_id) { + Some(guild) => guild.channels.get(&channel_id).is_some(), - if !channel_exists { - return false; - } - - let channel_matches_guild = - channel.map_or(false, |c| c.guild(&ctx.cache).map_or(false, |g| g.id == guild_id)); - - channel_matches_guild + None => false, + }; } async fn create_database_channel(