Update opt out method

This commit is contained in:
Skylar Grant 2023-02-19 20:32:04 -05:00
parent b0a9a6a42c
commit fc7bc1c332
4 changed files with 16 additions and 31 deletions

View File

@ -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 </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.", "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 </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
"reset": "All guild configuration information has been removed from the database.", "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.", "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 </setup rolemenu:0> to create a role menu." "noRoleMenu": "A role menu has not been created for this guild yet. Run </setup rolemenu:0> to create a role menu.",
"optout": "Notification relay has been disabled, to re-enable the relay use </notifications update:0> with no options."
}, },
"notifications": { "notifications": {
"water": "is ready to be watered again!", "water": "is ready to be watered again!",

View File

@ -23,6 +23,7 @@ module.exports = {
this.fruitRoleId = ""; this.fruitRoleId = "";
this.reminderChannelId = ""; this.reminderChannelId = "";
this.watchChannelId = ""; this.watchChannelId = "";
this.notificationsEnabled = false;
} }
setId(id) { setId(id) {
@ -47,11 +48,12 @@ module.exports = {
this.leaderboardChannelId = channelId; this.leaderboardChannelId = channelId;
return this; return this;
} }
setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId) { setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) {
this.waterMessage = waterMessage; if (waterMessage) this.waterMessage = waterMessage;
this.fruitMessage = fruitMessage; if (fruitMessage) this.fruitMessage = fruitMessage;
this.reminderChannelId = reminderChannelId; if (reminderChannelId) this.reminderChannelId = reminderChannelId;
this.watchChannelId = watchChannelId; if (watchChannelId) this.watchChannelId = watchChannelId;
if (enabled) this.notificationsEnabled = enabled;
return this; return this;
} }
setRoles(waterRoleId, fruitRoleId) { setRoles(waterRoleId, fruitRoleId) {
@ -102,16 +104,18 @@ module.exports = {
break; break;
case "setReminders": case "setReminders":
queryParts = [ 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.guildId)},`,
`${db.escape(this.waterMessage)},`, `${db.escape(this.waterMessage)},`,
`${db.escape(this.fruitMessage)},`, `${db.escape(this.fruitMessage)},`,
`${db.escape(this.reminderChannelId)},`, `${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)}, `, `) ON DUPLICATE KEY UPDATE water_message = ${db.escape(this.waterMessage)}, `,
`fruit_message = ${db.escape(this.fruitMessage)}, `, `fruit_message = ${db.escape(this.fruitMessage)}, `,
`reminder_channel_id = ${db.escape(this.reminderChannelId)}, `, `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(''); return queryParts.join('');
break; break;

View File

@ -68,7 +68,7 @@ module.exports = {
.setHeight(row.tree_height) .setHeight(row.tree_height)
.setTreeMessage(row.tree_message_id, row.tree_channel_id) .setTreeMessage(row.tree_message_id, row.tree_channel_id)
.setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_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); .setRoles(row.water_role_id, row.fruit_role_id);
db.end(); db.end();
resolve(guildInfo); resolve(guildInfo);
@ -111,7 +111,7 @@ module.exports = {
.setHeight(row.tree_height) .setHeight(row.tree_height)
.setTreeMessage(row.tree_message_id, row.tree_channel_id) .setTreeMessage(row.tree_message_id, row.tree_channel_id)
.setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_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) .setRoles(row.water_role_id, row.fruit_role_id)
); );
} }

View File

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