diff --git a/CustomModules/ButtonHandlers.js b/CustomModules/ButtonHandlers.js index f28b878..cf3d6d9 100644 --- a/CustomModules/ButtonHandlers.js +++ b/CustomModules/ButtonHandlers.js @@ -34,6 +34,12 @@ module.exports = { case 'nextRequestsPage': module.exports.requestsPage(interaction); break; + case 'prevJointsPage': + module.exports.jointsPage(interaction); + break; + case 'nextJointsPage': + module.exports.jointsPage(interaction); + break; default: return; } @@ -115,5 +121,31 @@ module.exports = { } interaction.update(fn.embeds.requests({command: "/requests", author: interaction.member.displayName}, indexedRequests)); + }, + jointsPage(interaction) { + const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); + + switch (interaction.component.customId) { + case 'prevJointsPage': + if (iStorage.page > 0) { + iStorage.page = iStorage.page - 1; + } + break; + case 'nextJointsPage': + if (iStorage.page < interaction.client.joints.size / 10) { + iStorage.page = iStorage.page + 1; + } + break; + default: + break; + } + const indexedJoints = indexer(interaction.client.joints, iStorage.page); + indexedJoints.jointsString = new String(); + + for (const joint of indexedJoints.thisPage) { + indexedJoints.jointsString += `${joint.content}\n`; + } + + interaction.update(fn.embeds.joints({command: "/joints", author: interaction.member.displayName}, indexedJoints)); } } \ No newline at end of file diff --git a/CustomModules/Embeds.js b/CustomModules/Embeds.js index 3264174..115e66a 100644 --- a/CustomModules/Embeds.js +++ b/CustomModules/Embeds.js @@ -107,6 +107,31 @@ module.exports = { break; } + // Put the buttons into an ActionRow + return new MessageActionRow() + .addComponents(previousButton, nextButton); + }, + jointsPageAR(state) { + // Setup the buttons + const previousButton = new MessageButton() + .setCustomId('prevJointsPage') + .setLabel('⬅️') + .setStyle('SECONDARY'); + + const nextButton = new MessageButton() + .setCustomId('nextJointsPage') + .setLabel('➡️') + .setStyle('SECONDARY'); + + switch (state) { + case 'first': + previousButton.setDisabled(true); + break; + case 'last': + nextButton.setDisabled(true); + break; + } + // Put the buttons into an ActionRow return new MessageActionRow() .addComponents(previousButton, nextButton); diff --git a/functions.js b/functions.js index 15b8caa..f606849 100644 --- a/functions.js +++ b/functions.js @@ -271,6 +271,16 @@ const functions = { const gifsPageAR = customEmbeds.gifsPageAR(indexedGifs.state); return { embeds: [gifsEmbed], components: [gifsPageAR], ephemeral: true }; }, + joints(commandData, indexedJoints) { + const jointsEmbed = new Discord.MessageEmbed() + .setAuthor({name: commandData.command}) + .setTimestamp() + .setFooter({text: `Page: ${indexedJoints.pagesString}`}) + .setDescription(indexedJoints.jointsString); + + const jointsPageAR = customEmbeds.jointsPageAR(indexedJoints.state); + return { embeds: [jointsEmbed], components: [jointsPageAR], ephemeral: true }; + }, text(commandData) { return { embeds: [new Discord.MessageEmbed() .setAuthor({name: commandData.command}) diff --git a/slash-commands/joints.js b/slash-commands/joints.js index 2ca5b6c..bca4490 100644 --- a/slash-commands/joints.js +++ b/slash-commands/joints.js @@ -1,15 +1,29 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const fn = require('../functions.js'); +const indexer = require('../CustomModules/Indexer.js'); module.exports = { data: new SlashCommandBuilder() .setName('joints') .setDescription('Send a list of all the /joint phrases.'), async execute(interaction) { - let joints = []; - interaction.client.joints.map(e => { - joints.push(e.content); - }); - interaction.reply({ content: 'Here are all the `.joint` phrases I have saved:\n\n' + joints.join('\n'), ephemeral: true }); + if (!interaction.client.joints) { + interaction.reply('For some reason I don\'t have access to the collection of joints. Sorry about that!'); + return; + } + let iStorage = interaction.client.iStorage.get(interaction.id); + let indexedJoints = indexer(interaction.client.joints, 0); + indexedJoints.jointsString = new String(); + + iStorage.page = 0; + + for (const joint of indexedJoints.thisPage) { + indexedJoints.jointsString += `${joint.content}\n`; + } + const commandData = { + command: "/joints", + author: interaction.member.displayName + }; + interaction.reply(fn.embeds.joints(commandData, indexedJoints)); }, }; \ No newline at end of file