MVP for paged /joints
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 55s

This commit is contained in:
Skylar Grant 2024-09-26 08:47:42 -04:00
parent c3fa30ea64
commit d0528c3637
4 changed files with 86 additions and 5 deletions

View File

@ -34,6 +34,12 @@ module.exports = {
case 'nextRequestsPage': case 'nextRequestsPage':
module.exports.requestsPage(interaction); module.exports.requestsPage(interaction);
break; break;
case 'prevJointsPage':
module.exports.jointsPage(interaction);
break;
case 'nextJointsPage':
module.exports.jointsPage(interaction);
break;
default: default:
return; return;
} }
@ -115,5 +121,31 @@ module.exports = {
} }
interaction.update(fn.embeds.requests({command: "/requests", author: interaction.member.displayName}, indexedRequests)); 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));
} }
} }

View File

@ -107,6 +107,31 @@ module.exports = {
break; 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 // Put the buttons into an ActionRow
return new MessageActionRow() return new MessageActionRow()
.addComponents(previousButton, nextButton); .addComponents(previousButton, nextButton);

View File

@ -271,6 +271,16 @@ const functions = {
const gifsPageAR = customEmbeds.gifsPageAR(indexedGifs.state); const gifsPageAR = customEmbeds.gifsPageAR(indexedGifs.state);
return { embeds: [gifsEmbed], components: [gifsPageAR], ephemeral: true }; 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) { text(commandData) {
return { embeds: [new Discord.MessageEmbed() return { embeds: [new Discord.MessageEmbed()
.setAuthor({name: commandData.command}) .setAuthor({name: commandData.command})

View File

@ -1,15 +1,29 @@
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const fn = require('../functions.js'); const fn = require('../functions.js');
const indexer = require('../CustomModules/Indexer.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('joints') .setName('joints')
.setDescription('Send a list of all the /joint phrases.'), .setDescription('Send a list of all the /joint phrases.'),
async execute(interaction) { async execute(interaction) {
let joints = []; if (!interaction.client.joints) {
interaction.client.joints.map(e => { interaction.reply('For some reason I don\'t have access to the collection of joints. Sorry about that!');
joints.push(e.content); return;
}); }
interaction.reply({ content: 'Here are all the `.joint` phrases I have saved:\n\n' + joints.join('\n'), ephemeral: true }); 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));
}, },
}; };