v3.3.3: Paged Commands #20
@ -5,6 +5,14 @@ const fn = require('../functions.js');
|
||||
|
||||
module.exports = {
|
||||
baseEvent(interaction) {
|
||||
let iStorage;
|
||||
if (interaction.client.iStorage.has(interaction.message.interaction.id)) {
|
||||
iStorage = interaction.client.iStorage.get(interaction.message.interaction.id)
|
||||
} else {
|
||||
iStorage = new InteractionStorage(interaction.message.interaction.id, interaction);
|
||||
iStorage.page = 0;
|
||||
}
|
||||
if (interaction.user.id !== iStorage.userId) return;
|
||||
switch (interaction.component.customId) {
|
||||
// Any of the gifsPage Buttons
|
||||
case 'prevGifsPage':
|
||||
@ -13,19 +21,18 @@ module.exports = {
|
||||
case 'nextGifsPage':
|
||||
module.exports.gifsPage(interaction);
|
||||
break;
|
||||
case 'prevPastasPage':
|
||||
module.exports.pastasPage(interaction);
|
||||
break;
|
||||
case 'nextPastasPage':
|
||||
module.exports.pastasPage(interaction);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
},
|
||||
gifsPage(interaction) {
|
||||
let iStorage;
|
||||
if (interaction.client.iStorage.has(interaction.message.interaction.id)) {
|
||||
iStorage = interaction.client.iStorage.get(interaction.message.interaction.id)
|
||||
} else {
|
||||
iStorage = new InteractionStorage(interaction.message.interaction.id, interaction);
|
||||
iStorage.page = 0;
|
||||
}
|
||||
console.log('Beginning Page: ' + iStorage.page);
|
||||
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
|
||||
|
||||
switch (interaction.component.customId) {
|
||||
case 'prevGifsPage':
|
||||
@ -48,8 +55,32 @@ module.exports = {
|
||||
indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`;
|
||||
}
|
||||
|
||||
console.log('Ending Page: ' + iStorage.page);
|
||||
|
||||
interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.member.displayName}, indexedGifs));
|
||||
},
|
||||
pastasPage(interaction) {
|
||||
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
|
||||
|
||||
switch (interaction.component.customId) {
|
||||
case 'prevPastasPage':
|
||||
if (iStorage.page > 0) {
|
||||
iStorage.page = iStorage.page - 1;
|
||||
}
|
||||
break;
|
||||
case 'nextPastasPage':
|
||||
if (iStorage.page < interaction.client.pastas.size / 10) {
|
||||
iStorage.page = iStorage.page + 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const indexedPastas = indexer(interaction.client.pastas, iStorage.page);
|
||||
indexedPastas.pastasString = new String();
|
||||
|
||||
for (const pasta of indexedPastas.thisPage) {
|
||||
indexedPastas.pastasString += `${pasta.name}.pasta\n`;
|
||||
}
|
||||
|
||||
interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.member.displayName}, indexedPastas));
|
||||
}
|
||||
}
|
@ -87,30 +87,29 @@ module.exports = {
|
||||
return new MessageActionRow()
|
||||
.addComponents(previousButton, confirmButton, nextButton, cancelButton);
|
||||
},
|
||||
pastasPageAR() {
|
||||
pastasPageAR(state) {
|
||||
// Setup the buttons
|
||||
const previousButton = new MessageButton()
|
||||
.setCustomId('prevPastasPage')
|
||||
.setLabel('⬅️')
|
||||
.setStyle('SECONDARY');
|
||||
|
||||
const confirmButton = new MessageButton()
|
||||
.setCustomId('confirmPastasPage')
|
||||
.setLabel('✅')
|
||||
.setStyle('PRIMARY');
|
||||
|
||||
const nextButton = new MessageButton()
|
||||
.setCustomId('nextPastasPage')
|
||||
.setLabel('➡️')
|
||||
.setStyle('SECONDARY');
|
||||
|
||||
const cancelButton = new MessageButton()
|
||||
.setCustomId('cancelPastasPage')
|
||||
.setLabel('❌')
|
||||
.setStyle('DANGER');
|
||||
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, confirmButton, nextButton, cancelButton);
|
||||
.addComponents(previousButton, nextButton);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
module.exports = class InteractionStorage {
|
||||
constructor(idString, interaction) {
|
||||
this.idString = idString;
|
||||
this.userId = interaction.user.id;
|
||||
|
||||
// Store in the client
|
||||
interaction.client.iStorage.set(idString, this);
|
||||
|
16
functions.js
16
functions.js
@ -251,21 +251,15 @@ const functions = {
|
||||
.setTimestamp()
|
||||
.setFooter({text: commandData.author})]};
|
||||
},
|
||||
pastas(commandData) {
|
||||
const pastasArray = [];
|
||||
pastas(commandData, indexedPastas) {
|
||||
const pastasEmbed = new Discord.MessageEmbed()
|
||||
.setAuthor({name: commandData.command})
|
||||
.setTimestamp()
|
||||
.setFooter({text: commandData.author});
|
||||
.setFooter({text: `Page: ${indexedPastas.pagesString}`})
|
||||
.setDescription(indexedPastas.pastasString);
|
||||
|
||||
for (const row of commandData.pastas) {
|
||||
pastasArray.push(`#${row.id} - ${row.name}.pasta`);
|
||||
}
|
||||
|
||||
const pastasString = pastasArray.join('\n');
|
||||
pastasEmbed.setDescription(pastasString);
|
||||
|
||||
return { embeds: [pastasEmbed], ephemeral: true };
|
||||
const pastasPageAR = customEmbeds.pastasPageAR(indexedPastas.state);
|
||||
return { embeds: [pastasEmbed], components: [pastasPageAR], ephemeral: true };
|
||||
},
|
||||
gifs(commandData, indexedGifs) {
|
||||
const gifsEmbed = new Discord.MessageEmbed()
|
||||
|
@ -8,10 +8,9 @@ module.exports = {
|
||||
.setName('gifs')
|
||||
.setDescription('Get a list of currently saved GIFs.'),
|
||||
execute(interaction) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!interaction.client.gifs) {
|
||||
interaction.reply('For some reason I don\'t have access to the collection of gifs. Sorry about that!');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
let iStorage = interaction.client.iStorage.get(interaction.id);
|
||||
let indexedGifs = indexer(interaction.client.gifs, 0);
|
||||
@ -27,6 +26,5 @@ module.exports = {
|
||||
author: interaction.member.displayName
|
||||
};
|
||||
interaction.reply(fn.embeds.gifs(commandData, indexedGifs));
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { config } = require('dotenv');
|
||||
const fn = require('../functions.js');
|
||||
const indexer = require('../CustomModules/Indexer.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
@ -11,23 +12,19 @@ module.exports = {
|
||||
interaction.reply({ content: 'For some reason I don\'t have access to the collection of copypastas. Sorry about that!', ephemeral: true });
|
||||
return;
|
||||
}
|
||||
const commandData = {
|
||||
author: interaction.user.tag,
|
||||
command: interaction.commandName,
|
||||
pastas: [],
|
||||
};
|
||||
const pastasMap = interaction.client.pastas.map(e => {
|
||||
return {
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
};
|
||||
});
|
||||
for (const row of pastasMap) {
|
||||
commandData.pastas.push({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
});
|
||||
let iStorage = interaction.client.iStorage.get(interaction.id);
|
||||
let indexedPastas = indexer(interaction.client.pastas, 0);
|
||||
indexedPastas.pastasString = new String();
|
||||
|
||||
iStorage.page = 0;
|
||||
|
||||
for (const pasta of indexedPastas.thisPage) {
|
||||
indexedPastas.pastasString += `${pasta.name}.pasta\n`;
|
||||
}
|
||||
interaction.reply(fn.embeds.pastas(commandData));
|
||||
const commandData = {
|
||||
command: "/pastas",
|
||||
author: interaction.member.displayName
|
||||
};
|
||||
interaction.reply(fn.embeds.pastas(commandData, indexedPastas));
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user