From c93077016de9c5f350e2939e8968ff03e8ce1cb5 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 12 Feb 2023 11:46:06 -0500 Subject: [PATCH] Begin implementing role menu --- modules/CustomClasses.js | 16 +++++++++++++++- modules/functions.js | 3 ++- slash-commands/notifications.js | 1 + slash-commands/rolemenu.js | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 slash-commands/rolemenu.js diff --git a/modules/CustomClasses.js b/modules/CustomClasses.js index 8bf12d3..23f9b90 100644 --- a/modules/CustomClasses.js +++ b/modules/CustomClasses.js @@ -18,7 +18,9 @@ module.exports = { this.leaderboardMessageId = ""; this.leaderboardChannelId = ""; this.waterMessage = ""; + this.waterRoleId = ""; this.fruitMessage = ""; + this.fruitRoleId = ""; this.reminderChannelId = ""; this.watchChannelId = ""; } @@ -52,6 +54,10 @@ module.exports = { this.watchChannelId = watchChannelId; return this; } + setRoles(waterRoleId, fruitRoleId) { + this.waterRoleId = waterRoleId; + if (fruitRoleId) this.fruitRoleId = fruitRoleId; + } queryBuilder(query) { let queryParts = []; switch (query) { @@ -119,7 +125,15 @@ module.exports = { ]; return queryParts.join(''); break; - default: + case "setRoles": + queryParts = [ + `UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `, + `fruit_role_id = ${db.escape(this.fruitRoleId)}, `, + `WHERE guild_id = ${db.escape(this.guildId)}` + ]; + return queryParts.join(''); + break; + default: break; } } diff --git a/modules/functions.js b/modules/functions.js index 5ae448d..75d90de 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -537,9 +537,10 @@ const functions = { const collector = channel.createMessageCollector({ filter }); collector.on('collect', message => { if (message.embeds.length == 0) return; + console.log(message.embeds); if (message.embeds[0].data.description.includes(strings.notifications.water)) { this.sendReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); - } else if (message.embeds[0].data.descriprion.includes(strings.notifications.fruit)) { + } else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) { this.sendReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); } }); diff --git a/slash-commands/notifications.js b/slash-commands/notifications.js index ea75a78..89fe976 100644 --- a/slash-commands/notifications.js +++ b/slash-commands/notifications.js @@ -41,6 +41,7 @@ module.exports = { console.log(query); await dbfn.setGuildInfo(query); await interaction.editReply(`I'll watch <#${watchChannel.id}> for Grow A Tree Notifications and relay them to <#${reminderChannel.id}>.`).catch(e => console.error(e)); + fn.collectionBuilders.guildInfos(interaction.client); } } catch (err) { console.error("Error occurred while setting up a notification relay: " + err); diff --git a/slash-commands/rolemenu.js b/slash-commands/rolemenu.js new file mode 100644 index 0000000..39806c8 --- /dev/null +++ b/slash-commands/rolemenu.js @@ -0,0 +1,20 @@ +const { SlashCommandBuilder } = require('discord.js'); +const fn = require('../modules/functions.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('rolemenu') + .setDescription('Send a self-assignable role selection menu') + .addRoleOption(o => + o.setName('waterrole') + .setDescription('The role for water reminder pings') + .setRequired(true)) + .addRoleOption(o => + o.setName('fruitrole') + .setDescription('The role for fruit alert pings') + .setRequired(false)), + async execute(interaction) { + await interaction.deferReply().catch(err => console.error(err)); + await interaction.editReply(fn.builders.embeds.treeRoleMenu()).catch(err => console.error(err)); + }, +}; \ No newline at end of file