MVP for paged /joints
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 55s
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 55s
This commit is contained in:
parent
c3fa30ea64
commit
d0528c3637
@ -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));
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
10
functions.js
10
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})
|
||||
|
@ -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));
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user