diff --git a/commands/editprofile.js b/commands/editprofile.js index 7331d12..349c54f 100644 --- a/commands/editprofile.js +++ b/commands/editprofile.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder, ComponentType, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder } = require("discord.js"); const { Card, User, Character } = require("../models"); -const UserUtils = require("../util/users"); +const { UserUtils, ReplyUtils } = require("../util"); const pageSize = 8; @@ -11,6 +11,7 @@ module.exports = { .setDescription("Edit your profile"), permissionLevel: 0, async execute(interaction) { + await interaction.deferReply(); let user = await UserUtils.getUserByDiscordId(interaction.member.id); let profile = await user.getProfile(); @@ -18,8 +19,8 @@ module.exports = { //row of button components to select what property to edit - const row = new ActionRowBuilder(); - row.addComponents( + const mainRow = new ActionRowBuilder(); + mainRow.addComponents( new ButtonBuilder() .setLabel('Edit Status') .setCustomId('editStatus') @@ -30,25 +31,66 @@ module.exports = { .setStyle(ButtonStyle.Primary) ); + const pingRow = new ActionRowBuilder(); + pingRow.addComponents( + new ButtonBuilder() + .setLabel('Wishlist Ping') + .setCustomId('toggle-wishlist-ping') + .setStyle(user.wishlistPing ? ButtonStyle.Success : ButtonStyle.Primary), + new ButtonBuilder() + .setLabel('Drop Ping') + .setCustomId('toggle-drop-ping') + .setStyle(user.dropPing ? ButtonStyle.Success : ButtonStyle.Primary), + new ButtonBuilder() + .setLabel('Daily Ping') + .setCustomId('toggle-daily-ping') + .setStyle(user.dailyPing ? ButtonStyle.Success : ButtonStyle.Primary) + ); + //show buttons - let message = await interaction.reply({ content: "", components: [row], fetchReply: true }); + let message = await interaction.editReply({ content: "", components: [mainRow, pingRow], fetchReply: true }); //filter only events from the user who triggered the command const filter = (m) => m.author.id === interaction.author.id; const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 25000 }) - collector.on('collect', async (m) => { - switch (m.customId) { + collector.on('collect', async (i) => { + await i.deferReply(); + switch (i.customId) { case 'editStatus': - await this.openStatusModal(m, user, profile); + await this.openStatusModal(i, user, profile); break; case 'editShowcase': - await this.openShowcaseModal(m, user, profile); + await this.openShowcaseModal(i, user, profile); + break; + case 'toggle-wishlist-ping': + user.wishlistPing = !user.wishlistPing; + user.save(); + break; + case 'toggle-drop-ping': + user.dropPing = !user.dropPing; + user.save(); + break; + case 'toggle-daily-ping': + user.dailyPing = !user.dailyPing; + user.save(); break; default: - m.reply({ content: "Invalid selection" }); + i.editReply({ content: "Invalid selection" }); + return; break; } + + let newComponents= ReplyUtils.recreateComponents(message.components); + newComponents[1].components.forEach(component => { + if(component.data.custom_id == i.customId) { + component.setStyle((component.data.style == 1) ? 3 : 1); + console.log(`Changed style of ${component.data.custom_id} is now ${component.data.style}`); + } + }); + await message.edit({ components: newComponents }); + let msg = await i.editReply({content: '...'}); + await msg.delete(); }); }, async openShowcaseModal(interaction, user, profile) {