From e6aeb685eed8a351676b8e1f358ca000856f5df1 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 12 Feb 2023 16:00:04 -0500 Subject: [PATCH] Fixes, ready for testing --- main.js | 6 ++++-- modules/CustomClasses.js | 3 ++- modules/dbfn.js | 7 ++++--- modules/functions.js | 11 +++++++++++ slash-commands/rolemenu.js | 3 +++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 740156f..20cd257 100644 --- a/main.js +++ b/main.js @@ -72,10 +72,12 @@ client.on('interactionCreate', async interaction => { } break; case 'waterpingrole': - await interaction.reply(fn.buttonHandlers.waterPing(interaction)).catch(err => console.error(err)); + const waterPingStatus = await fn.buttonHandlers.waterPing(interaction); + await interaction.reply(waterPingStatus).catch(err => console.error(err)); break; case 'fruitpingrole': - await interaction.reply(fn.buttonHandlers.fruitPing(interaction)).catch(err => console.error(err)); + const fruitPingStatus = await fn.buttonHandlers.fruitPing(interaction); + await interaction.reply(fruitPingStatus).catch(err => console.error(err)); break; default: break; diff --git a/modules/CustomClasses.js b/modules/CustomClasses.js index 23f9b90..f528fdf 100644 --- a/modules/CustomClasses.js +++ b/modules/CustomClasses.js @@ -57,6 +57,7 @@ module.exports = { setRoles(waterRoleId, fruitRoleId) { this.waterRoleId = waterRoleId; if (fruitRoleId) this.fruitRoleId = fruitRoleId; + return this; } queryBuilder(query) { let queryParts = []; @@ -128,7 +129,7 @@ module.exports = { case "setRoles": queryParts = [ `UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `, - `fruit_role_id = ${db.escape(this.fruitRoleId)}, `, + `fruit_role_id = ${db.escape(this.fruitRoleId)} `, `WHERE guild_id = ${db.escape(this.guildId)}` ]; return queryParts.join(''); diff --git a/modules/dbfn.js b/modules/dbfn.js index 086a224..3729f80 100644 --- a/modules/dbfn.js +++ b/modules/dbfn.js @@ -68,8 +68,8 @@ 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) + .setRoles(row.water_role_id, row.fruit_role_id); db.end(); resolve(guildInfo); }); @@ -112,6 +112,7 @@ module.exports = { .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) + .setRoles(row.water_role_id, row.fruit_role_id) ); } @@ -134,7 +135,7 @@ module.exports = { return new Promise((resolve, reject) => { db.query(query, (err, res) => { if (err) { - console.error(err); + console.error(err + "\n" + query); reject("Error setting the guild info: " + err.message); db.end(); return; diff --git a/modules/functions.js b/modules/functions.js index 57494f8..7fdab79 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -507,6 +507,17 @@ const functions = { } } }, + roles: { + async fetchRole(guild, roleId) { + return await guild.roles.fetch(roleId).catch(err => console.error("Error fetching the role: " + err + "\n" + roleId)); + }, + async giveRole(member, role) { + await member.roles.add(role).catch(err => console.error("Error giving the role: " + err + "\n" + JSON.stringify(role))); + }, + async takeRole(member, role) { + await member.roles.remove(role).catch(err => console.error("Error taking the role: " + err + "\n" + JSON.stringify(role))); + } + }, async refresh(interaction) { // const getGuildInfoResponse = await dbfn.getGuildInfo(interaction.guildId); // let guildInfo = getGuildInfoResponse.data; diff --git a/slash-commands/rolemenu.js b/slash-commands/rolemenu.js index 13f39d5..5f1a479 100644 --- a/slash-commands/rolemenu.js +++ b/slash-commands/rolemenu.js @@ -1,4 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); +const dbfn = require('../modules/dbfn.js'); const fn = require('../modules/functions.js'); module.exports = { @@ -18,6 +19,8 @@ module.exports = { if (interaction.client.guildInfos.has(interaction.guildId)) { let guildInfo = interaction.client.guildInfos.get(interaction.guildId); guildInfo.setRoles(interaction.options.getRole('waterrole').id, interaction.options.getRole('fruitrole').id); + await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles")); + await fn.collectionBuilders.guildInfos(interaction.client); await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(err => console.error(err)); } else { await interaction.editReply(fn.builders.errorEmbed("No information is known about your server yet, please run /setup or /compare")).catch(err => console.error(err));