create guild data if not present. added a temp method to reattach channels to their guild data

This commit is contained in:
jude 2020-10-27 11:37:55 +00:00
parent d7b0d18444
commit b08848d272
5 changed files with 23 additions and 7 deletions

2
Cargo.lock generated
View File

@ -1175,7 +1175,7 @@ dependencies = [
[[package]]
name = "reminder_rs"
version = "1.1.2"
version = "1.1.3"
dependencies = [
"Inflector",
"async-trait",

View File

@ -1,6 +1,6 @@
[package]
name = "reminder_rs"
version = "1.1.2"
version = "1.1.3"
authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018"

View File

@ -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))
}
};

View File

@ -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())

View File

@ -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!(
"