From 2fea17b23d06ef5943c153fefa3143ff0b986010 Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 27 Dec 2023 18:16:36 -0700 Subject: [PATCH] delete existing vote reminders when opted out --- scripty_commands/src/cmds/vote_reminders.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripty_commands/src/cmds/vote_reminders.rs b/scripty_commands/src/cmds/vote_reminders.rs index 40c1569..742ac11 100644 --- a/scripty_commands/src/cmds/vote_reminders.rs +++ b/scripty_commands/src/cmds/vote_reminders.rs @@ -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, @@ -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,