From c5fddd12cf097ddc63e03b79ffad0d3d8521f582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Mon, 12 Sep 2022 13:39:06 +0200 Subject: [PATCH] Profile: Allow editing of customStatus using the editprofile command Editprofile itself now shows buttons to select different subcommands. --- commands/editprofile.js | 77 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/commands/editprofile.js b/commands/editprofile.js index 674c8c7..658c9e3 100644 --- a/commands/editprofile.js +++ b/commands/editprofile.js @@ -13,8 +13,44 @@ module.exports = { let user = await UserUtils.getUserByDiscordId(interaction.member.id); let profile = await user.getProfile(); - console.log(profile['slotOne']); + + + //row of button components to select what property to edit + const row = new ActionRowBuilder(); + row.addComponents( + new ButtonBuilder() + .setLabel('Edit Status') + .setCustomId('editStatus') + .setStyle(ButtonStyle.Primary), + new ButtonBuilder() + .setLabel('Edit Showcase') + .setCustomId('editShowcase') + .setStyle(ButtonStyle.Primary) + ); + + //show buttons + let message = await interaction.reply({ content: "", components: [row], 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) { + case 'editStatus': + await this.openStatusModal(m, user, profile); + break; + case 'editShowcase': + await this.openShowcaseModal(m, user, profile); + break; + default: + m.reply({ content: "Invalid selection" }); + break; + } + }); + }, + async openShowcaseModal(interaction, user, profile) { const modal = new ModalBuilder() .setCustomId('cardSlotModal') .setTitle('Edit card showcase'); @@ -35,7 +71,6 @@ module.exports = { modal.addComponents(cardIDComponenets); } - let message = await interaction.showModal(modal); let submitted = await interaction.awaitModalSubmit({ @@ -63,5 +98,43 @@ module.exports = { content: `Updated showcase`, }) } + }, + async openStatusModal(interaction, user, profile) { + const modal = new ModalBuilder() + .setCustomId('descriptionModal') + .setTitle('Edit profile status/description'); + + let row = new ActionRowBuilder(); + let statusInput = new TextInputBuilder() + .setCustomId('profileStatus') + .setLabel(`Your status`) + .setStyle(TextInputStyle.Paragraph) + .setRequired(false) + .setMaxLength(155) + .setPlaceholder(profile.customStatus ? profile.customStatus.slice(0,90) + '...' : "No status set"); + row.addComponents(statusInput); + modal.addComponents(row); + + let message = await interaction.showModal(modal); + + let submitted = await interaction.awaitModalSubmit({ + time: 300000, + filter: i => i.user.id === interaction.user.id, + }).catch(error => { + //Error includes timeout + console.error(error) + return null + }) + + if (submitted) { + let updatePayload = {}; + if (submitted.fields.getTextInputValue('profileStatus') != profile.customStatus) { + profile.update({customStatus: submitted.fields.getTextInputValue('profileStatus')}); + } + await submitted.reply({ + content: `Updated status`, + }) + } } + } \ No newline at end of file