Skip to content

Commit

Permalink
Adds attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Mar 1, 2024
1 parent f9b3a84 commit 26b54a4
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports.Pagination = class {
pageList: null,
imageList: null,
buttonList: null,
attachmentList: null,
// Pagination
pagination: null
}
Expand Down Expand Up @@ -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}
Expand Down
17 changes: 16 additions & 1 deletion src/lib/InteractionPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/lib/MessagePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/lib/PaginationBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports.PaginationBase = async({
pageList: null,
imageList: null,
buttonList: null,
attachmentList: null,
// Pagination
pagination: null
},
Expand Down Expand Up @@ -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]]
}
Expand All @@ -110,13 +114,20 @@ 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]]
}
) : await paginationInfo.portal.reply(options.imageList ?
{
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
Expand Down Expand Up @@ -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]]
}
Expand All @@ -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]]
}
Expand Down
1 change: 1 addition & 0 deletions wiki/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.setPageList()
.setImageList()
.setButtonList()
.setAttachmentList()
.setTimeout()
.setProgressBar()
.enableReplyMessage()
Expand Down
23 changes: 23 additions & 0 deletions wiki/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* <a href="#setButtonList">`setButtonList`</a> - This is used to set the buttons to be used by the pagination
* <a href="#setPageList">`setPageList`</a> - This is used to set the pages used in the pagination
* <a href="#setImageList">`setImageList`</a> - This is used to set the images used for the pagination
* <a href="#setAttachmentList"> `setAttachmentList`</a> - This is used to set the attachment list for the embeds
* <a href="#paginate">`paginate`</a> - This is used run the pagination
***
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26b54a4

Please sign in to comment.