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