From 2cc13e832885736f2b67bec28a53ba14b60b9d56 Mon Sep 17 00:00:00 2001 From: Supositware Date: Wed, 5 Apr 2023 16:12:56 +0000 Subject: [PATCH] Update a bunch of buttons --- commands/AI/img2img.js | 24 ++++++++++------ commands/AI/txt2img.js | 24 ++++++++++------ commands/admin/autoresponse.js | 38 ++++++++++++++----------- commands/admin/bye.js | 52 +++++++++++++++++++--------------- commands/admin/quotation.js | 35 +++++++++++++---------- commands/admin/tag.js | 46 +++++++++++++++++------------- commands/admin/welcome.js | 52 +++++++++++++++++++--------------- commands/owner/ublacklist.js | 34 +++++++++++++--------- commands/utility/optout.js | 35 ++++++++++++++--------- 9 files changed, 197 insertions(+), 143 deletions(-) diff --git a/commands/AI/img2img.js b/commands/AI/img2img.js index cff78c39..3874afbe 100644 --- a/commands/AI/img2img.js +++ b/commands/AI/img2img.js @@ -116,21 +116,14 @@ async function generate(i, prompt, client, b64Img) { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`regenerate${i.user.id}`) + .setCustomId(`regenerate${i.user.id}${i.id}`) .setLabel('🔄 Regenerate') .setStyle(ButtonStyle.Primary), ); await i.editReply({ embeds: [stableEmbed], components: [row], files: [generatedImg] }); - client.once('interactionCreate', async (interactionMenu) => { - if (i.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - if (interactionMenu.customId === `regenerate${interactionMenu.user.id}`) { - await interactionMenu.deferReply(); - await generate(interactionMenu, prompt, client); - } - }); + listenButton(client, i, prompt); } }, wait_time); } @@ -151,3 +144,16 @@ async function checkGeneration(url) { return { done: true, image: check.generations[0].img, seed: check.generations[0].seed, worker_id: check.generations[0].worker_id, worker_name: check.generations[0].worker_name }; } } + +async function listenButton(client, interaction, prompt) { + client.once('interactionCreate', async (interactionMenu) => { + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `regenerate${interactionMenu.user.id}${interaction.id}`) { + await interactionMenu.deferReply(); + await generate(interactionMenu, prompt, client); + } + }); +} \ No newline at end of file diff --git a/commands/AI/txt2img.js b/commands/AI/txt2img.js index 9b9b97e8..baad72d5 100644 --- a/commands/AI/txt2img.js +++ b/commands/AI/txt2img.js @@ -101,21 +101,14 @@ async function generate(i, prompt, client) { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`regenerate${i.user.id}`) + .setCustomId(`regenerate${i.user.id}${i.id}`) .setLabel('🔄 Regenerate') .setStyle(ButtonStyle.Primary), ); await i.editReply({ embeds: [stableEmbed], components: [row], files: [generatedImg] }); - client.once('interactionCreate', async (interactionMenu) => { - if (i.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - if (interactionMenu.customId === `regenerate${interactionMenu.user.id}`) { - await interactionMenu.deferReply(); - await generate(interactionMenu, prompt, client); - } - }); + listenButton(client, i, prompt); } }, wait_time); } @@ -136,3 +129,16 @@ async function checkGeneration(url) { return { done: true, image: check.generations[0].img, seed: check.generations[0].seed, worker_id: check.generations[0].worker_id, worker_name: check.generations[0].worker_name }; } } + +async function listenButton(client, interaction, prompt) { + client.once('interactionCreate', async (interactionMenu) => { + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `regenerate${interactionMenu.user.id}${interaction.id}`) { + await interactionMenu.deferReply(); + await generate(interactionMenu, prompt, client); + } + }); +} \ No newline at end of file diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js index 65480f6f..1ea09231 100644 --- a/commands/admin/autoresponse.js +++ b/commands/admin/autoresponse.js @@ -19,13 +19,13 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`yes${interaction.user.id}`) + .setCustomId(`yes${interaction.user.id}${interaction.id}`) .setLabel('Yes') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`no${interaction.user.id}`) + .setCustomId(`no${interaction.user.id}${interaction.id}`) .setLabel('No') .setStyle(ButtonStyle.Danger), ); @@ -39,18 +39,24 @@ export default { return interaction.editReply({ content: 'Auto response has been enabled.', ephemeral: true }); } - client.on('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `yes${interaction.user.id}`) { - const body = { serverID: interaction.guild.id, stat: 'disable' }; - await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } }); - return interaction.editReply({ content: 'Auto response has been disabled.', ephemeral: true }); - } - else { - return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); - } - }); + return listenButton(client, interaction, interaction.user); }, -}; \ No newline at end of file +}; + +async function listenButton(client, interaction, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) { + const body = { serverID: interaction.guild.id, stat: 'disable' }; + await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } }); + return interaction.editReply({ content: 'Auto response has been disabled.', ephemeral: true }); + } + else { + return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); + } + }); +} \ No newline at end of file diff --git a/commands/admin/bye.js b/commands/admin/bye.js index c905ca00..37a1a923 100644 --- a/commands/admin/bye.js +++ b/commands/admin/bye.js @@ -25,44 +25,50 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`edit${interaction.user.id}`) + .setCustomId(`edit${interaction.user.id}${interaction.id}`) .setLabel('Edit') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`remove${interaction.user.id}`) + .setCustomId(`remove${interaction.user.id}${interaction.id}`) .setLabel('Remove') .setStyle(ButtonStyle.Danger), ) .addComponents( new ButtonBuilder() - .setCustomId(`nothing${interaction.user.id}`) + .setCustomId(`nothing${interaction.user.id}${interaction.id}`) .setLabel('Do nothing') .setStyle(ButtonStyle.Secondary), ); await interaction.reply({ content: 'The server already has a message set, do you want to edit it or remove it?', components: [row], ephemeral: true }); - client.on('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `edit${interaction.user.id}`) { - if (!args.message) { - return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true }); - } - const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message }; - await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } }); - return interaction.editReply({ content: `The leave message has been set to ${args.message}`, ephemeral: true }); - } - else if (interactionMenu.customId === `remove${interaction.user.id}`) { - db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } }); - return interaction.editReply({ content: 'The leave message has been deleted.', ephemeral: true }); - } - else { - return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); - } - }); + return listenButton(client, interaction, args, interaction.user); }, }; + +async function listenButton(client, interaction, args, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, args, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `edit${interaction.user.id}${originalId}`) { + if (!args.message) { + return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true }); + } + const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message }; + await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } }); + return interaction.editReply({ content: `The leave message has been set to ${args.message}`, ephemeral: true }); + } + else if (interactionMenu.customId === `remove${interaction.user.id}${originalId}`) { + db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } }); + return interaction.editReply({ content: 'The leave message has been deleted.', ephemeral: true }); + } + else { + return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); + } + }); +} \ No newline at end of file diff --git a/commands/admin/quotation.js b/commands/admin/quotation.js index ef388e24..d63835cd 100644 --- a/commands/admin/quotation.js +++ b/commands/admin/quotation.js @@ -20,13 +20,13 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`yes${interaction.user.id}`) + .setCustomId(`yes${interaction.user.id}${interaction.id}`) .setLabel('Yes') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`no${interaction.user.id}`) + .setCustomId(`no${interaction.user.id}${interaction.id}`) .setLabel('No') .setStyle(ButtonStyle.Danger), ); @@ -40,18 +40,23 @@ export default { return interaction.editReply({ content: 'Quotation has been enabled.', ephemeral: true }); } - client.on('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `yes${interaction.user.id}`) { - const body = { serverID: interaction.guild.id, stat: 'disable' }; - await db.quotationStat.update(body, { where: { serverID: interaction.guild.id } }); - return interaction.editReply({ content: 'Quotation has been disabled.', ephemeral: true }); - } - else { - return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); - } - }); + return listenButton(client, interaction, interaction.user); }, }; + +async function listenButton(client, interaction, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, user, originalId); + if (!interactionMenu.isButton()) return; + + interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) { + await db.quotationStat.destroy({ where: { serverID: interaction.guild.id } }); + return interaction.editReply({ content: 'Quotation has been disabled.', ephemeral: true }); + } + else { + return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); + } + }); +} \ No newline at end of file diff --git a/commands/admin/tag.js b/commands/admin/tag.js index 40e45d09..82f10bde 100644 --- a/commands/admin/tag.js +++ b/commands/admin/tag.js @@ -77,45 +77,51 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`edit${interaction.user.id}`) + .setCustomId(`edit${interaction.user.id}${interaction.id}`) .setLabel('Edit') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`remove${interaction.user.id}`) + .setCustomId(`remove${interaction.user.id}${interaction.id}`) .setLabel('Remove') .setStyle(ButtonStyle.Danger), ) .addComponents( new ButtonBuilder() - .setCustomId(`nothing${interaction.user.id}`) + .setCustomId(`nothing${interaction.user.id}${interaction.id}`) .setLabel('Do nothing') .setStyle(ButtonStyle.Secondary), ); await interaction.editReply({ content: 'This tag already exist, do you want to update it, remove it or do nothing?', components: [row], ephemeral: true }); - client.once('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - await interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `edit${interaction.user.id}`) { - const body = { trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: interaction.guild.id }; - await db.Tag.update(body, { where: { serverID: interaction.guild.id } }); - return interaction.editReply({ content: `The tag ${args.trigger} has been set to ${args.response}`, ephemeral: true }); - } - else if (interactionMenu.customId === `remove${interaction.user.id}`) { - db.Tag.destroy({ where: { trigger: args.trigger, serverID: interaction.guild.id } }); - return interaction.editReply({ content: `The tag ${args.trigger} has been deleted`, ephemeral: true }); - } - else { - return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); - } - }); + return listenButton(client, interaction, args, interaction.user); } else { return interaction.editReply(`You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${this.client.commandHandler.prefix[0]}tag ${args.trigger} --remove`); } }, }; + +async function listenButton(client, interaction, args, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, args, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `edit${interaction.user.id}${originalId}`) { + const body = { trigger: args.trigger, response: args.response, ownerID: interaction.user.id, serverID: interaction.guild.id }; + db.Tag.update(body, { where: { serverID: interaction.guild.id } }); + return interaction.editReply({ content: `The tag ${args.trigger} has been set to ${args.response}`, ephemeral: true }); + } + else if (interactionMenu.customId === `remove${interaction.user.id}${originalId}`) { + db.Tag.destroy({ where: { trigger: args.trigger, serverID: interaction.guild.id } }); + return interaction.editReply({ content: `The tag ${args.trigger} has been deleted`, ephemeral: true }); + } + else { + return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); + } + }); +} \ No newline at end of file diff --git a/commands/admin/welcome.js b/commands/admin/welcome.js index 351597bf..ec97b02a 100644 --- a/commands/admin/welcome.js +++ b/commands/admin/welcome.js @@ -26,44 +26,50 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`edit${interaction.user.id}`) + .setCustomId(`edit${interaction.user.id}${interaction.id}`) .setLabel('Edit') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`remove${interaction.user.id}`) + .setCustomId(`remove${interaction.user.id}${interaction.id}`) .setLabel('Remove') .setStyle(ButtonStyle.Danger), ) .addComponents( new ButtonBuilder() - .setCustomId(`nothing${interaction.user.id}`) + .setCustomId(`nothing${interaction.user.id}${interaction.id}`) .setLabel('Do nothing') .setStyle(ButtonStyle.Secondary), ); await interaction.reply({ content: 'The server already has a message set, do you want to edit it or remove it?', components: [row], ephemeral: true }); - client.on('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `edit${interaction.user.id}`) { - if (!args.message) { - return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true }); - } - const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message }; - await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } }); - return interaction.editReply({ content: `The join message has been set to ${args.message}`, ephemeral: true }); - } - else if (interactionMenu.customId === `remove${interaction.user.id}`) { - db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } }); - return interaction.editReply({ content: 'The join message has been deleted.', ephemeral: true }); - } - else { - return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); - } - }); + return listenButton(client, interaction, args, interaction.user); }, }; + +async function listenButton(client, interaction, args, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, args, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `edit${interaction.user.id}${originalId}`) { + if (!args.message) { + return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true }); + } + const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message }; + await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } }); + return interaction.editReply({ content: `The join message has been set to ${args.message}`, ephemeral: true }); + } + else if (interactionMenu.customId === `remove${interaction.user.id}${originalId}`) { + db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } }); + return interaction.editReply({ content: 'The join message has been deleted.', ephemeral: true }); + } + else { + return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true }); + } + }); +} \ No newline at end of file diff --git a/commands/owner/ublacklist.js b/commands/owner/ublacklist.js index 9b9be361..18b751f0 100644 --- a/commands/owner/ublacklist.js +++ b/commands/owner/ublacklist.js @@ -43,31 +43,37 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`yes${interaction.user.id}`) + .setCustomId(`yes${interaction.user.id}${interaction.id}`) .setLabel('Yes') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`no${interaction.user.id}`) + .setCustomId(`no${interaction.user.id}${interaction.id}`) .setLabel('No') .setStyle(ButtonStyle.Danger), ); await interaction.editReply({ content: 'This user is already blacklisted, do you want to unblacklist him?', ephemeral: true, components: [row] }); - interaction.client.once('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `yes${interaction.user.id}`) { - Blacklists.destroy({ where: { type:command, uid:userid } }); - return interaction.editReply(`The following ID have been unblacklisted from ${command}: ${userid}`); - } - else { - return interaction.editReply('No one has been unblacklisted.'); - } - }); + return listenButton(client, interaction, command, userid, interaction.user); } }, }; + +async function listenButton(client, interaction, command, userid, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, command, userid, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) { + Blacklists.destroy({ where: { type:command, uid:userid } }); + return interaction.editReply(`The following ID have been unblacklisted from ${command}: ${userid}`); + } + else { + return interaction.editReply('No one has been unblacklisted.'); + } + }); +} \ No newline at end of file diff --git a/commands/utility/optout.js b/commands/utility/optout.js index c88414fe..abc9e9e9 100644 --- a/commands/utility/optout.js +++ b/commands/utility/optout.js @@ -18,30 +18,37 @@ export default { const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId(`yes${interaction.user.id}`) + .setCustomId(`yes${interaction.user.id}${interaction.id}`) .setLabel('Yes') .setStyle(ButtonStyle.Primary), ) .addComponents( new ButtonBuilder() - .setCustomId(`no${interaction.user.id}`) + .setCustomId(`no${interaction.user.id}${interaction.id}`) .setLabel('No') .setStyle(ButtonStyle.Danger), ); await interaction.reply({ content: 'You are already opt out, do you wish to opt in?', components: [row] }); - client.on('interactionCreate', async (interactionMenu) => { - if (interaction.user !== interactionMenu.user) return; - if (!interactionMenu.isButton) return; - interactionMenu.update({ components: [] }); - if (interactionMenu.customId === `yes${interaction.user.id}`) { - await db.optout.destroy({ where: { userID: interaction.user.id } }); - return interaction.editReply('You have successfully been opt in'); - } - else { - return interaction.editReply('Nothing has been changed.'); - } - }); + return listenButton(client, interaction, interaction.user); }, }; + + +async function listenButton(client, interaction, user = interaction.user, originalId = interaction.id) { + client.once('interactionCreate', async (interactionMenu) => { + if (user !== interactionMenu.user) return listenButton(client, interaction, user, originalId); + if (!interactionMenu.isButton()) return; + + await interactionMenu.update({ components: [] }); + + if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) { + db.optout.destroy({ where: { userID: interaction.user.id } }); + return interaction.editReply('You have successfully been opt in'); + } + else { + return interaction.editReply('Nothing has been changed.'); + } + }); +} \ No newline at end of file