From b08848d2726e52581320b43e3ce235657a546f8a Mon Sep 17 00:00:00 2001 From: jude Date: Tue, 27 Oct 2020 11:37:55 +0000 Subject: [PATCH] create guild data if not present. added a temp method to reattach channels to their guild data --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/reminder_cmds.rs | 2 +- src/framework.rs | 11 +++++++---- src/models.rs | 13 +++++++++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bbcb6f..076a8ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1175,7 +1175,7 @@ dependencies = [ [[package]] name = "reminder_rs" -version = "1.1.2" +version = "1.1.3" dependencies = [ "Inflector", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index a14ad59..fccfea1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder_rs" -version = "1.1.2" +version = "1.1.3" authors = ["jellywx "] edition = "2018" diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 7bf9613..9dee337 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -466,7 +466,7 @@ LIMIT .unwrap() .as_secs(); - longhand_displacement(reminder.time as u64 - now) + longhand_displacement((reminder.time as u64).checked_sub(now).unwrap_or(0)) } }; diff --git a/src/framework.rs b/src/framework.rs index 5fd58ca..bf8ccca 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -360,6 +360,7 @@ impl Framework for RegexFramework { .expect("Could not get SQLPool from data"); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); + let guild_data = GuildData::from_guild(guild.clone(), &pool).await.unwrap(); match check_self_permissions(&ctx, &guild, &channel).await { Ok(perms) => match perms { @@ -373,11 +374,13 @@ impl Framework for RegexFramework { msg.channel(&ctx).await.unwrap(), &pool, ) - .await; + .await + .unwrap(); - if !command.can_blacklist - || !channel_data.map(|c| c.blacklisted).unwrap_or(false) - { + // required due to a small bug resulting in some channels being detached from their guild ids + channel_data.update_guild_id(guild_data.id, &pool).await; + + if !command.can_blacklist || !channel_data.blacklisted { let args = full_match .name("args") .map(|m| m.as_str()) diff --git a/src/models.rs b/src/models.rs index ac25897..e543340 100644 --- a/src/models.rs +++ b/src/models.rs @@ -158,6 +158,19 @@ SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_u } } + pub async fn update_guild_id(&self, id: u32, pool: &MySqlPool) { + sqlx::query!( + " +UPDATE channels SET guild_id = ? WHERE id = ? + ", + id, + self.id + ) + .execute(pool) + .await + .unwrap(); + } + pub async fn commit_changes(&self, pool: &MySqlPool) { sqlx::query!( "