55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
const customEmbeds = require('../CustomModules/Embeds.js');
|
|
const InteractionStorage = require('../CustomModules/InteractionStorage.js');
|
|
const indexer = require('../CustomModules/Indexer.js');
|
|
const fn = require('../functions.js');
|
|
|
|
module.exports = {
|
|
baseEvent(interaction) {
|
|
switch (interaction.component.customId) {
|
|
// Any of the gifsPage Buttons
|
|
case 'prevGifsPage':
|
|
module.exports.gifsPage(interaction);
|
|
break;
|
|
case 'nextGifsPage':
|
|
module.exports.gifsPage(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);
|
|
|
|
switch (interaction.component.customId) {
|
|
case 'prevGifsPage':
|
|
if (iStorage.page > 0) {
|
|
iStorage.page = iStorage.page - 1;
|
|
}
|
|
break;
|
|
case 'nextGifsPage':
|
|
if (iStorage.page < interaction.client.gifs.size / 10) {
|
|
iStorage.page = iStorage.page + 1;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
const indexedGifs = indexer(interaction.client.gifs, iStorage.page);
|
|
indexedGifs.gifsString = new String();
|
|
|
|
for (const gif of indexedGifs.thisPage) {
|
|
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));
|
|
}
|
|
} |