From fc7bc1c3326105868dd5e8ecf92aa273887c67e1 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 19 Feb 2023 20:32:04 -0500 Subject: [PATCH] Update opt out method --- data/strings.json | 3 ++- modules/CustomClasses.js | 20 ++++++++++++-------- modules/dbfn.js | 4 ++-- slash-commands/optout.js | 20 -------------------- 4 files changed, 16 insertions(+), 31 deletions(-) delete mode 100755 slash-commands/optout.js diff --git a/data/strings.json b/data/strings.json index ed7f0a6..184e013 100755 --- a/data/strings.json +++ b/data/strings.json @@ -63,7 +63,8 @@ "missingTreeChannel": "There was a problem finding the Tree channel, was it deleted? Please make sure the ``/tree`` and ``/top trees`` messages are in this channel, or run to set the ``/tree`` and ``/top trees`` channels.", "reset": "All guild configuration information has been removed from the database.", "resetError": "There was a problem deleting your guild information, contact @voidf1sh#0420 for help.", - "noRoleMenu": "A role menu has not been created for this guild yet. Run to create a role menu." + "noRoleMenu": "A role menu has not been created for this guild yet. Run to create a role menu.", + "optout": "Notification relay has been disabled, to re-enable the relay use with no options." }, "notifications": { "water": "is ready to be watered again!", diff --git a/modules/CustomClasses.js b/modules/CustomClasses.js index 7c72c7c..c35730f 100755 --- a/modules/CustomClasses.js +++ b/modules/CustomClasses.js @@ -23,6 +23,7 @@ module.exports = { this.fruitRoleId = ""; this.reminderChannelId = ""; this.watchChannelId = ""; + this.notificationsEnabled = false; } setId(id) { @@ -47,11 +48,12 @@ module.exports = { this.leaderboardChannelId = channelId; return this; } - setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId) { - this.waterMessage = waterMessage; - this.fruitMessage = fruitMessage; - this.reminderChannelId = reminderChannelId; - this.watchChannelId = watchChannelId; + setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) { + if (waterMessage) this.waterMessage = waterMessage; + if (fruitMessage) this.fruitMessage = fruitMessage; + if (reminderChannelId) this.reminderChannelId = reminderChannelId; + if (watchChannelId) this.watchChannelId = watchChannelId; + if (enabled) this.notificationsEnabled = enabled; return this; } setRoles(waterRoleId, fruitRoleId) { @@ -102,16 +104,18 @@ module.exports = { break; case "setReminders": queryParts = [ - `INSERT INTO guild_info (guild_id, water_message, fruit_message, reminder_channel_id, watch_channel_id) VALUES (`, + `INSERT INTO guild_info (guild_id, water_message, fruit_message, reminder_channel_id, watch_channel_id, notifications_enabled) VALUES (`, `${db.escape(this.guildId)},`, `${db.escape(this.waterMessage)},`, `${db.escape(this.fruitMessage)},`, `${db.escape(this.reminderChannelId)},`, - `${db.escape(this.watchChannelId)}`, + `${db.escape(this.watchChannelId)},`, + `${db.escape(this.notificationsEnabled)}`, `) ON DUPLICATE KEY UPDATE water_message = ${db.escape(this.waterMessage)}, `, `fruit_message = ${db.escape(this.fruitMessage)}, `, `reminder_channel_id = ${db.escape(this.reminderChannelId)}, `, - `watch_channel_id = ${db.escape(this.watchChannelId)}` + `watch_channel_id = ${db.escape(this.watchChannelId)},`, + `notifications_enabled = ${db.escape(this.notificationsEnabled)}` ]; return queryParts.join(''); break; diff --git a/modules/dbfn.js b/modules/dbfn.js index 8168061..2eb1854 100755 --- a/modules/dbfn.js +++ b/modules/dbfn.js @@ -68,7 +68,7 @@ module.exports = { .setHeight(row.tree_height) .setTreeMessage(row.tree_message_id, row.tree_channel_id) .setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_channel_id) - .setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id) + .setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id, row.notifications_enabled) .setRoles(row.water_role_id, row.fruit_role_id); db.end(); resolve(guildInfo); @@ -111,7 +111,7 @@ module.exports = { .setHeight(row.tree_height) .setTreeMessage(row.tree_message_id, row.tree_channel_id) .setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_channel_id) - .setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id) + .setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id, row.notifications_enabled) .setRoles(row.water_role_id, row.fruit_role_id) ); } diff --git a/slash-commands/optout.js b/slash-commands/optout.js deleted file mode 100755 index 1d1cf37..0000000 --- a/slash-commands/optout.js +++ /dev/null @@ -1,20 +0,0 @@ -const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); -const dbfn = require('../modules/dbfn.js'); -const fn = require('../modules/functions.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('optout') - .setDescription('Opt-out of automatic water reminders') - .setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles), - async execute(interaction) { - try { - await interaction.deferReply({ ephemeral: true }); - const setReminderOptInResponse = await dbfn.setReminderOptIn(interaction.guildId, 0); - interaction.editReply(setReminderOptInResponse.status); - } catch(err) { - console.error(err); - await interaction.editReply(fn.builders.errorEmbed(err)); - } - }, -}; \ No newline at end of file