2024-09-26 03:22:22 +00:00
|
|
|
const customEmbeds = require('../CustomModules/Embeds.js');
|
2024-09-26 12:09:09 +00:00
|
|
|
const InteractionStorage = require('../CustomModules/InteractionStorage.js');
|
|
|
|
const indexer = require('../CustomModules/Indexer.js');
|
|
|
|
const fn = require('../functions.js');
|
2024-09-26 23:30:41 +00:00
|
|
|
const { GifData } = require('./NodBot.js');
|
2024-09-26 03:22:22 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
baseEvent(interaction) {
|
2024-09-26 12:27:11 +00:00
|
|
|
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;
|
2024-09-26 03:22:22 +00:00
|
|
|
switch (interaction.component.customId) {
|
|
|
|
// Any of the gifsPage Buttons
|
2024-09-26 12:09:09 +00:00
|
|
|
case 'prevGifsPage':
|
|
|
|
module.exports.gifsPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'nextGifsPage':
|
|
|
|
module.exports.gifsPage(interaction);
|
2024-09-26 03:22:22 +00:00
|
|
|
break;
|
2024-09-26 12:27:11 +00:00
|
|
|
case 'prevPastasPage':
|
|
|
|
module.exports.pastasPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'nextPastasPage':
|
|
|
|
module.exports.pastasPage(interaction);
|
|
|
|
break;
|
2024-09-26 12:37:16 +00:00
|
|
|
case 'prevRequestsPage':
|
|
|
|
module.exports.requestsPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'nextRequestsPage':
|
|
|
|
module.exports.requestsPage(interaction);
|
|
|
|
break;
|
2024-09-26 12:47:42 +00:00
|
|
|
case 'prevJointsPage':
|
|
|
|
module.exports.jointsPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'nextJointsPage':
|
|
|
|
module.exports.jointsPage(interaction);
|
|
|
|
break;
|
2024-09-26 23:30:41 +00:00
|
|
|
case 'prevGif':
|
|
|
|
module.exports.gifSearchPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'nextGif':
|
|
|
|
module.exports.gifSearchPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'confirmGif':
|
|
|
|
module.exports.gifSearchPage(interaction);
|
|
|
|
break;
|
|
|
|
case 'cancelGif':
|
|
|
|
module.exports.gifSearchPage(interaction);
|
|
|
|
break;
|
2024-09-29 17:01:25 +00:00
|
|
|
case 'closeRequests':
|
|
|
|
module.exports.closeRequests(interaction);
|
|
|
|
break;
|
2024-09-26 03:22:22 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2024-09-26 12:09:09 +00:00
|
|
|
gifsPage(interaction) {
|
2024-09-26 12:27:11 +00:00
|
|
|
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
|
2024-09-26 12:09:09 +00:00
|
|
|
|
|
|
|
switch (interaction.component.customId) {
|
2024-09-26 03:22:22 +00:00
|
|
|
case 'prevGifsPage':
|
2024-09-26 12:09:09 +00:00
|
|
|
if (iStorage.page > 0) {
|
|
|
|
iStorage.page = iStorage.page - 1;
|
|
|
|
}
|
|
|
|
break;
|
2024-09-26 03:22:22 +00:00
|
|
|
case 'nextGifsPage':
|
2024-09-26 12:09:09 +00:00
|
|
|
if (iStorage.page < interaction.client.gifs.size / 10) {
|
|
|
|
iStorage.page = iStorage.page + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2024-09-26 03:22:22 +00:00
|
|
|
}
|
2024-09-26 12:09:09 +00:00
|
|
|
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`;
|
|
|
|
}
|
|
|
|
|
2024-09-29 16:17:07 +00:00
|
|
|
interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.user.username}, indexedGifs));
|
2024-09-26 12:27:11 +00:00
|
|
|
},
|
|
|
|
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`;
|
|
|
|
}
|
|
|
|
|
2024-09-29 16:17:07 +00:00
|
|
|
interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.user.username}, indexedPastas));
|
2024-09-26 12:37:16 +00:00
|
|
|
},
|
|
|
|
requestsPage(interaction) {
|
|
|
|
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
|
|
|
|
|
|
|
|
switch (interaction.component.customId) {
|
|
|
|
case 'prevRequestsPage':
|
|
|
|
if (iStorage.page > 0) {
|
|
|
|
iStorage.page = iStorage.page - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'nextRequestsPage':
|
|
|
|
if (iStorage.page < interaction.client.requests.size / 10) {
|
|
|
|
iStorage.page = iStorage.page + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const indexedRequests = indexer(interaction.client.requests, iStorage.page);
|
|
|
|
indexedRequests.requestsString = new String();
|
|
|
|
|
|
|
|
for (const request of indexedRequests.thisPage) {
|
|
|
|
indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`;
|
|
|
|
}
|
|
|
|
|
2024-09-29 16:17:07 +00:00
|
|
|
interaction.update(fn.embeds.requests({command: "/requests", author: interaction.user.username}, indexedRequests));
|
2024-09-26 12:47:42 +00:00
|
|
|
},
|
|
|
|
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`;
|
|
|
|
}
|
|
|
|
|
2024-09-29 16:17:07 +00:00
|
|
|
interaction.update(fn.embeds.joints({command: "/joints", author: interaction.user.username}, indexedJoints));
|
2024-09-26 23:30:41 +00:00
|
|
|
},
|
|
|
|
gifSearchPage(interaction) {
|
|
|
|
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
|
|
|
|
|
|
|
|
switch (interaction.component.customId) {
|
|
|
|
case 'prevGif':
|
|
|
|
if (iStorage.page > 0) {
|
|
|
|
iStorage.page = iStorage.page - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'nextGif':
|
|
|
|
if (iStorage.page < interaction.client.gifs.size / 10) {
|
|
|
|
iStorage.page = iStorage.page + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'confirmGif':
|
|
|
|
const gif = indexer(iStorage.gifsCollection, iStorage.page, 1).thisPage[0];
|
|
|
|
const gifData = new GifData().setInfo(iStorage.gifName, gif.media_formats.gif.url, gif.id);
|
|
|
|
fn.upload.gif(gifData, interaction.client);
|
|
|
|
interaction.update({ content: `I've saved the GIF as ${gifData.name}.gif`, components: [] });
|
|
|
|
fn.download.gifs(interaction.client);
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case 'cancelGif':
|
|
|
|
interaction.update({ content: 'The GIF has been discarded.', components: [], embeds: [] });
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Generate the action row
|
|
|
|
const gifSearchAR = customEmbeds.actionRows.gifSearchAR(iStorage.state);
|
|
|
|
// Update the index
|
|
|
|
const indexedGifs = indexer(iStorage.gifsCollection, iStorage.page, 1);
|
|
|
|
indexedGifs.query = iStorage.query;
|
|
|
|
indexedGifs.gifName = iStorage.gifName;
|
|
|
|
// Generate the embed
|
2024-09-29 16:17:07 +00:00
|
|
|
const gifEmbed = customEmbeds.core.gifSearch({ author: interaction.user.username }, indexedGifs);
|
2024-09-26 23:30:41 +00:00
|
|
|
// Update the interaction
|
|
|
|
interaction.update({ embeds: [gifEmbed], components: [gifSearchAR], ephemeral: true });
|
2024-09-29 17:01:25 +00:00
|
|
|
},
|
|
|
|
closeRequests(interaction) {
|
|
|
|
const closeRequestModal = customEmbeds.modals.closeRequestsModal();
|
|
|
|
interaction.showModal(closeRequestModal);
|
|
|
|
interaction.update({ content: 'The requests menu has been closed.', components: [] });
|
2024-09-26 03:22:22 +00:00
|
|
|
}
|
|
|
|
}
|