From 14e350a555f74c62fd78d81f39980c8db30511e8 Mon Sep 17 00:00:00 2001 From: Emi <136156874+aho-emi@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:24:14 +0545 Subject: [PATCH 1/5] Create editButton.js --- src/functions/util/editButton.js | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/functions/util/editButton.js diff --git a/src/functions/util/editButton.js b/src/functions/util/editButton.js new file mode 100644 index 000000000..ad36aa495 --- /dev/null +++ b/src/functions/util/editButton.js @@ -0,0 +1,44 @@ +const { ButtonBuilder, ActionRowBuilder } = require('discord.js'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const inside = d.unpack(); + if (data.err) return d.error(data.err); + + let [index, customId, custom, label, style, disabled, emoji, messageId, channelId = d.channel.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelId); + if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); + const message = await d.util.getMessage(channel, messageId); + if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); + if (!customId) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Empty customId was provided"); + if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Index Provided In"); + index = Number(index) - 1; + if (style) { + style = d.util.constants.ButtonStyleOptions[style] || Number(style); + if (style > 5 || style < 1) d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Style Provided In"); + } + const components = message.components; + if (!components[index]) components[index] = { type: 1, components: [] }; + const rows = []; + components[index].components.forEach(button => { + if (button.customId === customId) { + const newButton = new ButtonBuilder() + .setLabel(label || button.label) + .setStyle(style || button.style) + .setDisabled(disabled ? JSON.parse(disabled) : button.disabled); + if (emoji) newButton.setEmoji(emoji || button.emoji); + style != 5 + ? newButton.setCustomId(custom || button.customId) + : newButton.setURL(custom || button.url); + rows.push(newButton); + } else { + rows.push(button); + } + }); + components[index] = new ActionRowBuilder().addComponents(rows); + await message.edit({ components }); + return { + code: d.util.setCode(data) + }; +}; From 6c7077ed17591e7f1266e8ef72d87289fcc2244a Mon Sep 17 00:00:00 2001 From: Emi <136156874+aho-emi@users.noreply.github.com> Date: Wed, 25 Oct 2023 07:43:32 +0545 Subject: [PATCH 2/5] Update editButton.js changes --- src/functions/util/editButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/util/editButton.js b/src/functions/util/editButton.js index ad36aa495..20e43b1f3 100644 --- a/src/functions/util/editButton.js +++ b/src/functions/util/editButton.js @@ -12,7 +12,7 @@ module.exports = async (d) => { const message = await d.util.getMessage(channel, messageId); if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); if (!customId) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Empty customId was provided"); - if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Index Provided In"); + if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In"); index = Number(index) - 1; if (style) { style = d.util.constants.ButtonStyleOptions[style] || Number(style); From a864344417863012d2898c9e9d3927d873c832c1 Mon Sep 17 00:00:00 2001 From: Emi <136156874+aho-emi@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:41:54 +0545 Subject: [PATCH 3/5] Update editButton.js --- src/functions/util/editButton.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/util/editButton.js b/src/functions/util/editButton.js index 20e43b1f3..d937b7c59 100644 --- a/src/functions/util/editButton.js +++ b/src/functions/util/editButton.js @@ -11,12 +11,12 @@ module.exports = async (d) => { if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); const message = await d.util.getMessage(channel, messageId); if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); - if (!customId) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Empty customId was provided"); + if (!customId) return d.aoiError.fnError(d, "custom", { inside }, "Empty customId was provided"); if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In"); index = Number(index) - 1; if (style) { style = d.util.constants.ButtonStyleOptions[style] || Number(style); - if (style > 5 || style < 1) d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Style Provided In"); + if (style > 5 || style < 1) d.aoiError.fnError(d, "custom", { inside }, "Invalid Style Provided In"); } const components = message.components; if (!components[index]) components[index] = { type: 1, components: [] }; From acb61558b2ed6b9ee18bfa5ad37ec4d02c940b19 Mon Sep 17 00:00:00 2001 From: Leref <12578483+Leref@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:21:05 -0400 Subject: [PATCH 4/5] updated params --- src/functions/util/editButton.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/util/editButton.js b/src/functions/util/editButton.js index d937b7c59..89bcdc480 100644 --- a/src/functions/util/editButton.js +++ b/src/functions/util/editButton.js @@ -5,11 +5,11 @@ module.exports = async (d) => { const inside = d.unpack(); if (data.err) return d.error(data.err); - let [index, customId, custom, label, style, disabled, emoji, messageId, channelId = d.channel.id] = data.inside.splits; + let [index, customId, custom, label, style, disabled, emoji, messageID, channelID = d.channel.id] = data.inside.splits; - const channel = await d.util.getChannel(d, channelId); + const channel = await d.util.getChannel(d, channelID); if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); - const message = await d.util.getMessage(channel, messageId); + const message = await d.util.getMessage(channel, messageID); if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); if (!customId) return d.aoiError.fnError(d, "custom", { inside }, "Empty customId was provided"); if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In"); From 7487860fc90f5198035cf014d8f866200c9361c8 Mon Sep 17 00:00:00 2001 From: Leref <12578483+Leref@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:22:37 -0400 Subject: [PATCH 5/5] updated to interaction path --- src/functions/{util => interaction}/editButton.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/functions/{util => interaction}/editButton.js (100%) diff --git a/src/functions/util/editButton.js b/src/functions/interaction/editButton.js similarity index 100% rename from src/functions/util/editButton.js rename to src/functions/interaction/editButton.js