diff --git a/package-lock.json b/package-lock.json index aa70c11..8c10078 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,9 +14,11 @@ "discord-api-types": "^0.36.3", "discord.js": "^14.3.0", "sqlite3": "^5.0.11", - "typescript": "^4.7.4" + "typescript": "^4.7.4", + "uuid": "^9.0.0" }, "devDependencies": { + "@types/uuid": "^9.0.0", "@typescript-eslint/eslint-plugin": "^5.30.7", "@typescript-eslint/parser": "^5.30.7", "dotenv": "^16.0.1", @@ -367,6 +369,12 @@ "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "dev": true }, + "node_modules/@types/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==", + "dev": true + }, "node_modules/@types/ws": { "version": "8.5.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", @@ -3179,6 +3187,14 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", @@ -3575,6 +3591,12 @@ "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "dev": true }, + "@types/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==", + "dev": true + }, "@types/ws": { "version": "8.5.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", @@ -5592,6 +5614,11 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==" + }, "v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/package.json b/package.json index 1fa46dc..658a33d 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,11 @@ "discord-api-types": "^0.36.3", "discord.js": "^14.3.0", "sqlite3": "^5.0.11", - "typescript": "^4.7.4" + "typescript": "^4.7.4", + "uuid": "^9.0.0" }, "devDependencies": { + "@types/uuid": "^9.0.0", "@typescript-eslint/eslint-plugin": "^5.30.7", "@typescript-eslint/parser": "^5.30.7", "dotenv": "^16.0.1", diff --git a/src/buttons/loader.ts b/src/buttons/loader.ts index 39a4630..0dbad68 100644 --- a/src/buttons/loader.ts +++ b/src/buttons/loader.ts @@ -43,9 +43,9 @@ export default async (client: Client) => { * @param id Button ID * @param deferUpdate defer update in case update take time */ -export const collect = (client: Client, interaction: ChatInputCommandInteraction, id: string, deferUpdate = false) => { +export const collect = (client: Client, interaction: ChatInputCommandInteraction | MessageComponentInteraction, id: string, deferUpdate = false) => { const loc = getLocale(client, interaction.locale); - const button = client.buttons.list.get(id); + const button = client.buttons.list.get(id.split('_')[0]); if (!button) { interaction.reply({ @@ -55,7 +55,7 @@ export const collect = (client: Client, interaction: ChatInputCommandInteraction } const filter = (i: MessageComponentInteraction) => i.customId === id; - const collector = interaction.channel?.createMessageComponentCollector({ filter }); + const collector = interaction.channel?.createMessageComponentCollector({ filter, max: 1 }); collector?.on('collect', async (i) => { if (deferUpdate) { await i.deferUpdate(); diff --git a/src/buttons/misc/reminderList-next.ts b/src/buttons/misc/reminderList-next.ts index 1d23761..76cc5ae 100644 --- a/src/buttons/misc/reminderList-next.ts +++ b/src/buttons/misc/reminderList-next.ts @@ -1,7 +1,9 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, MessageComponentInteraction, User } from 'discord.js'; +import { v4 as uuidv4 } from 'uuid'; import { getLocale } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; import { embedListReminders } from '../../utils/reminder'; +import { collect } from '../loader'; export default { data: { @@ -27,19 +29,25 @@ export default { // Fetch list const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale); + const idPrec = 'reminderList-prec_' + uuidv4(); + const idNext = 'reminderList-next_' + uuidv4(); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId('reminderList-prec') + .setCustomId(idPrec) .setLabel(loc.get('c_reminder12')) .setStyle(ButtonStyle.Primary)) .addComponents( new ButtonBuilder() - .setCustomId('reminderList-next') + .setCustomId(idNext) .setLabel(loc.get('c_reminder13')) .setStyle(ButtonStyle.Primary), ); + // Buttons interactions + collect(client, interaction, idPrec); + collect(client, interaction, idNext); + return { embeds: [list], components: [row], diff --git a/src/buttons/misc/reminderList-prec.ts b/src/buttons/misc/reminderList-prec.ts index 71e5cf4..06a1019 100644 --- a/src/buttons/misc/reminderList-prec.ts +++ b/src/buttons/misc/reminderList-prec.ts @@ -1,7 +1,9 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, MessageComponentInteraction, User } from 'discord.js'; +import { v4 as uuidv4 } from 'uuid'; import { getLocale } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; import { embedListReminders } from '../../utils/reminder'; +import { collect } from '../loader'; export default { data: { @@ -27,19 +29,25 @@ export default { // Fetch list const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale); + const idPrec = 'reminderList-prec_' + uuidv4(); + const idNext = 'reminderList-next_' + uuidv4(); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() - .setCustomId('reminderList-prec') + .setCustomId(idPrec) .setLabel(loc.get('c_reminder12')) .setStyle(ButtonStyle.Primary)) .addComponents( new ButtonBuilder() - .setCustomId('reminderList-next') + .setCustomId(idNext) .setLabel(loc.get('c_reminder13')) .setStyle(ButtonStyle.Primary), ); + // Buttons interactions + collect(client, interaction, idPrec); + collect(client, interaction, idNext); + return { embeds: [list], components: [row], diff --git a/src/commands/misc/reminder.ts b/src/commands/misc/reminder.ts index b6f2313..ee298db 100644 --- a/src/commands/misc/reminder.ts +++ b/src/commands/misc/reminder.ts @@ -1,5 +1,6 @@ import { ModalActionRowComponentBuilder, SlashCommandBuilder } from '@discordjs/builders'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, Client, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js'; +import { v4 as uuidv4 } from 'uuid'; import { collect } from '../../buttons/loader'; import { getLocale, getLocalizations } from '../../utils/locales'; import { getFilename } from '../../utils/misc'; @@ -222,8 +223,8 @@ export default { const page = interaction.options.getInteger(loc_default?.get(`c_${filename}_sub2_opt2_name`) as string) ?? 1; const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale); - const idPrec = 'reminderList-prec'; - const idNext = 'reminderList-next'; + const idPrec = 'reminderList-prec_' + uuidv4(); + const idNext = 'reminderList-next_' + uuidv4(); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder()