Skip to content

Commit

Permalink
delete existing vote reminders when opted out
Browse files Browse the repository at this point in the history
  • Loading branch information
tazz4843 committed Dec 28, 2023
1 parent 0c87aef commit 2fea17b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripty_commands/src/cmds/vote_reminders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ pub async fn vote_reminder(ctx: Context<'_>, enabled: bool) -> Result<(), Error>
scripty_i18n::get_resolved_language(ctx.author().id.get(), ctx.guild_id().map(|g| g.get()))
.await;

let user_id = ctx.author().id.get();
let db = scripty_db::get_db();
let hashed_user_id = scripty_utils::hash_user_id(ctx.author().id.get());
let hashed_user_id = scripty_utils::hash_user_id(user_id);
sqlx::query!(
"INSERT INTO users (user_id) VALUES ($1) ON CONFLICT ON CONSTRAINT users_pkey DO NOTHING",
hashed_user_id,
Expand All @@ -22,6 +23,14 @@ pub async fn vote_reminder(ctx: Context<'_>, enabled: bool) -> Result<(), Error>
)
.execute(db)
.await?;
if !enabled {
sqlx::query!(
"DELETE FROM vote_reminders WHERE user_id = $1",
user_id as i64,
)
.execute(db)
.await?;
}

ctx.say(format_message!(
resolved_language,
Expand Down

0 comments on commit 2fea17b

Please sign in to comment.