delete reminders when the user cannot be direct messaged

This commit is contained in:
jude 2022-05-14 10:56:03 +01:00
parent c4087bf569
commit 8eb46f1f23
2 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,7 @@ use regex::{Captures, Regex};
use serde::Deserialize;
use serenity::{
builder::CreateEmbed,
http::{CacheHttp, Http, StatusCode},
http::{CacheHttp, Http, HttpError, StatusCode},
model::{
channel::{Channel, Embed as SerenityEmbed},
id::ChannelId,
@ -569,11 +569,16 @@ UPDATE `channels` SET paused = 0, paused_until = NULL WHERE `channel` = ?
if let Error::Http(error) = e {
if error.status_code() == Some(StatusCode::NOT_FOUND) {
error!("Seeing channel is deleted. Removing reminder");
warn!("Seeing channel is deleted. Removing reminder");
self.force_delete(pool).await;
} else if let HttpError::UnsuccessfulRequest(error) = *error {
if error.error.code == 50007 {
warn!("User cannot receive DMs");
self.force_delete(pool).await;
} else {
self.refresh(pool).await;
}
}
} else {
self.refresh(pool).await;
}

View File

@ -71,7 +71,7 @@ INSERT IGNORE INTO channels (channel) VALUES (?)
sqlx::query!(
"
INSERT INTO users (user, dm_channel, timezone) VALUES (?, (SELECT id FROM channels WHERE channel = ?), ?)
INSERT INTO users (name, user, dm_channel, timezone) VALUES ('', ?, (SELECT id FROM channels WHERE channel = ?), ?)
",
user_id.0,
dm_channel.id.0,