Skip to content

Commit

Permalink
feat: allow embed templating
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Feb 3, 2022
1 parent a37e57b commit 4cd469e
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/PaginationEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ export class PaginationEmbed extends MessageEmbed {
* Sets the pagination embeds.
* Note: if you set this then all other pagination methods and embed methods will be ignored
* i.e., descriptions, images, fields, also the embed properties like title, footer and all
* @param embeds
* @param embeds An array of {@link MessageEmbed} or {@link MessageEmbedField}
* @param callback A callback function that will be called for each embed.
* @returns
* @example
* ```javascript
Expand All @@ -440,15 +441,23 @@ export class PaginationEmbed extends MessageEmbed {
* ```
*
*/
setEmbeds(embeds: Embed[]): this {
setEmbeds(
embeds: Embed[],
callback: (embed: MessageEmbed) => MessageEmbed
): this {
if (callback) {
embeds = embeds.map((e) =>
e instanceof MessageEmbed ? callback(e) : callback(new MessageEmbed(e))
);
}
this.embeds = embeds;
this.limit = 1;
return this;
}

/**
* Adds a pagination embed.
* @param embed
* @param embed A {@link MessageEmbed} or {@link MessageEmbedField}
* @returns
* @example
* ```javascript
Expand All @@ -465,7 +474,8 @@ export class PaginationEmbed extends MessageEmbed {

/**
* Adds multiple pagination embeds.
* @param embeds
* @param embeds An array of {@link MessageEmbed} or {@link MessageEmbedOptions}
* @param callback A callback function that will be called for each embed.
* @returns
* @example
* ```javascript
Expand All @@ -475,7 +485,15 @@ export class PaginationEmbed extends MessageEmbed {
* ```
*
*/
addEmbeds(embeds: Embed[]): this {
addEmbeds(
embeds: Embed[],
callback: (embed: MessageEmbed) => MessageEmbed
): this {
if (callback) {
embeds = embeds.map((e) =>
e instanceof MessageEmbed ? callback(e) : callback(new MessageEmbed(e))
);
}
this.embeds.push(...embeds);
return this;
}
Expand Down

0 comments on commit 4cd469e

Please # to comment.