From 26b54a4b28afc571a947a7ae4b242aac14a08e25 Mon Sep 17 00:00:00 2001 From: acegoal07 Date: Fri, 1 Mar 2024 23:53:32 +0000 Subject: [PATCH] Adds attachments --- package.json | 5 +++-- src/index.js | 14 ++++++++++++++ src/lib/InteractionPagination.js | 17 ++++++++++++++++- src/lib/MessagePagination.js | 14 ++++++++++++++ src/lib/PaginationBase.js | 20 ++++++++++++++++++++ wiki/Home.md | 1 + wiki/Usage.md | 23 +++++++++++++++++++++++ 7 files changed, 91 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2bea83e..d572678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acegoal07/discordjs-pagination", - "version": "1.5.8", + "version": "1.5.9", "description": "A simple pagination for Discord.js", "main": "index", "types": "types", @@ -25,7 +25,8 @@ }, "homepage": "https://github.com/acegoal07/discordjs-pagination#readme", "dependencies": { - "discord.js": "^14.7.1" + "discord.js": "^14.7.1", + "typescript": "^5.3.3" }, "scripts": { "build": "npm run buildTypes && npm run tscBuild && npm run copyFiles", diff --git a/src/index.js b/src/index.js index b3389f2..62ec15e 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ exports.Pagination = class { pageList: null, imageList: null, buttonList: null, + attachmentList: null, // Pagination pagination: null } @@ -113,6 +114,19 @@ exports.Pagination = class { this.options.imageList = true; return this; } + /** + * Sets the attachmentList for the pagination + * @param {import("discord.js").AttachmentBuilder[]} attachmentList + * @returns {exports.Pagination} + */ + setAttachmentList(attachmentList) { + // Checks + if (typeof attachmentList !== "object") {throw new Error("setAttachmentList ERROR: The attachmentList you have provided is not an object");} + if (!attachmentList || attachmentList.length === 0) {throw new Error("setAttachmentList ERROR: The attachmentList you have provided is empty");} + // Set and return + this.paginationInfo.attachmentList = attachmentList; + return this; + } /** * Run the pagination * @returns {exports.Pagination} diff --git a/src/lib/InteractionPagination.js b/src/lib/InteractionPagination.js index e2229a5..59706f8 100644 --- a/src/lib/InteractionPagination.js +++ b/src/lib/InteractionPagination.js @@ -12,6 +12,7 @@ const { ActionRowBuilder } = require("discord.js"), * pageList: import("discord.js").EmbedBuilder[], * imageList: import("discord.js").AttachmentBuilder[], * buttonList: import("discord.js").ButtonBuilder[], + * attachmentList: import("discord.js").AttachmentBuilder[], * pagination: null * }} paginationInfo * @param {{ @@ -52,6 +53,12 @@ exports.InteractionPagination = async(paginationInfo, options) => { components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], fetchReply: true, ephemeral: options.ephemeral + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], + fetchReply: true, + ephemeral: options.ephemeral } : { embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], @@ -125,7 +132,11 @@ exports.InteractionPagination = async(paginationInfo, options) => { { files: [paginationInfo.imageList[pageNumber]], fetchReply: true - } : { + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + fetchReply: true + } :{ embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], fetchReply: true } @@ -141,6 +152,10 @@ exports.InteractionPagination = async(paginationInfo, options) => { { files: [paginationInfo.imageList[pageNumber]], fetchReply: true + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + fetchReply: true } : { embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], fetchReply: true diff --git a/src/lib/MessagePagination.js b/src/lib/MessagePagination.js index 7e05501..2e41af3 100644 --- a/src/lib/MessagePagination.js +++ b/src/lib/MessagePagination.js @@ -12,6 +12,7 @@ const { ActionRowBuilder } = require("discord.js"), * pageList: import("discord.js").EmbedBuilder[], * imageList: import("discord.js").AttachmentBuilder[], * buttonList: import("discord.js").ButtonBuilder[], + * attachmentList: import("discord.js").AttachmentBuilder[], * pagination: null * }} paginationInfo * @param {{ @@ -51,6 +52,11 @@ exports.MessagePagination = async(paginationInfo, options) => { files: [paginationInfo.imageList[pageNumber]], components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], fetchReply: true + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], + fetchReply: true } : { embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], components: [options.selectMenu.toggle ? await SelectMenuCreator(pageLength, options.selectMenu.labels) : new ActionRowBuilder().addComponents(paginationInfo.buttonList)], @@ -122,6 +128,10 @@ exports.MessagePagination = async(paginationInfo, options) => { { files: [paginationInfo.imageList[pageNumber]], fetchReply: true + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + fetchReply: true } : { embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], fetchReply: true @@ -138,6 +148,10 @@ exports.MessagePagination = async(paginationInfo, options) => { { files: [paginationInfo.imageList[pageNumber]], fetchReply: true + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], + files: [paginationInfo.attachmentList[pageNumber] !== null ? paginationInfo.attachmentList[pageNumber] : null], + fetchReply: true } : { embeds: [paginationInfo.pageList[pageNumber].setFooter({text: `${options.progressBar.toggle ? `${await ProgressBarCreator(pageLength, pageNumber, options.progressBar)}` : `Page ${pageNumber + 1} / ${pageLength}`}`})], fetchReply: true diff --git a/src/lib/PaginationBase.js b/src/lib/PaginationBase.js index 1e51698..b69d5aa 100644 --- a/src/lib/PaginationBase.js +++ b/src/lib/PaginationBase.js @@ -17,6 +17,7 @@ exports.PaginationBase = async({ pageList: null, imageList: null, buttonList: null, + attachmentList: null, // Pagination pagination: null }, @@ -102,6 +103,9 @@ exports.PaginationBase = async({ return paginationInfo.portal.client.users.cache.get(paginationInfo.portal.member.user.id).send(options.imageList ? { files: [paginationInfo.imageList[0]] + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null] } : { embeds: [paginationInfo.pageList[0]] } @@ -110,6 +114,9 @@ exports.PaginationBase = async({ return paginationInfo.portal.deferred ? await paginationInfo.portal.editReply(options.imageList ? { files: [paginationInfo.imageList[0]] + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null] } : { embeds: [paginationInfo.pageList[0]] } @@ -117,6 +124,10 @@ exports.PaginationBase = async({ { files: [paginationInfo.imageList[0]], ephemeral: options.ephemeral + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null], + ephemeral: options.ephemeral } : { embeds: [paginationInfo.pageList[0]], ephemeral: options.ephemeral @@ -144,6 +155,9 @@ exports.PaginationBase = async({ return paginationInfo.portal.author.send(options.imageList ? { files: [paginationInfo.imageList[0]] + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null] } : { embeds: [paginationInfo.pageList[0]] } @@ -152,12 +166,18 @@ exports.PaginationBase = async({ return options.replyMessage ? paginationInfo.portal.reply(options.imageList ? { files: [paginationInfo.imageList[0]] + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null] } : { embeds: [paginationInfo.pageList[0]] } ) : paginationInfo.portal.channel.send(options.imageList ? { files: [paginationInfo.imageList[0]] + } : paginationInfo.attachmentList !== null ? { + embeds: [paginationInfo.pageList[0]], + files: [paginationInfo.attachmentList[0] !== null ? paginationInfo.attachmentList[0] : null] } : { embeds: [paginationInfo.pageList[0]] } diff --git a/wiki/Home.md b/wiki/Home.md index 6c6d692..ac4fea0 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -18,6 +18,7 @@ .setPageList() .setImageList() .setButtonList() +.setAttachmentList() .setTimeout() .setProgressBar() .enableReplyMessage() diff --git a/wiki/Usage.md b/wiki/Usage.md index 84ec94e..8327458 100644 --- a/wiki/Usage.md +++ b/wiki/Usage.md @@ -4,6 +4,7 @@ * `setButtonList` - This is used to set the buttons to be used by the pagination * `setPageList` - This is used to set the pages used in the pagination * `setImageList` - This is used to set the images used for the pagination +* `setAttachmentList` - This is used to set the attachment list for the embeds * `paginate` - This is used run the pagination *** @@ -110,6 +111,28 @@ const imageList = [ ]) ``` +*** +## `setAttachmentList` +> This is used to set the attachment list for the embed that can then be used for images + +**Parameters** +* `attachmentList` + +**Example** +```js +// Using const +const attachmentList = [ + new AttachmentBuilder(`img1.jpg`), + new AttachmentBuilder(`img2.jpg`) +] +.setAttachmentList(attachmentList) +// Inline +.setAttachmentList([ + new AttachmentBuilder(`img1.jpg`), + new AttachmentBuilder(`img2.jpg`) +]) +``` + *** ## `paginate` > This is used run the pagination for all the settings to work the paginate function need to be at the end of the functions