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.",
"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 </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": {
"water": "is ready to be watered again!",

View File

@ -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;

View File

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

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