import { ColorResolvable , EmbedField , EmbedFieldData , Message , MessageEmbed } from 'discord.js' ; import { PaginationEmbed } from './base' ; extends noInheritDoc export class Embeds extends PaginationEmbed < MessageEmbed > { /** The title of all embeds. */ public title : string ; /** The description of all embeds. */ public description : string ; /** The URL of all embeds. */ public url : string ; /** The color of all embeds. */ public color : number ; /** The timestamp of all embeds. */ public timestamp : number ; /** The fields of all embeds. */ public fields : EmbedField [ ] ; /** The thumbnail of all embeds. */ public thumbnail : string ; /** The image of all embeds. */ public image : string ; /** The author of all embeds. */ public author : { name : string ; url ? : string ; iconURL ? : string ; } ; /** The footer of all embeds. */ public footer : { text : string ; iconURL ? : string ; } ; /** Embed in the current page. */ get currentEmbed ( ) : MessageEmbed { return this . array [ this . page - 1 ] ; } get pages ( ) : number { return this . array . length ; } param name param value param inline public addField ( name , value , inline = false ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . addField ( name , value , inline ) ; return this ; } public addFields ( ... fields ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . addFields ( ... fields ) ; return this ; } /**
     * Build the Pagination Embeds.
     *
     * ### Example
     * ```js
     *   const { Embeds } = require('discord-paginationembed');
     *   const { MessageEmbed } = require('discord.js');
     *
     *   // Under message event.
     *   const embeds = [];
     *
     *   for (let i = 0; i < 5; ++i)
     *    embeds.push(new MessageEmbed().addField('Page', i + 1));
     *
     *   new Embeds()
     *    .setAuthorizedUsers([message.author.id])
     *    .setChannel(message.channel)
     *    .setClientAssets({ prompt: 'Yo {{user}} wat peige?!?!?' })
     *    .setArray(embeds)
     *    .setPageIndicator(false)
     *    .setPage(1)
     *    .setTimeout(69000)
     *    .setNavigationEmojis({
     *      back: '◀',
     *      jump: '↗',
     *      forward: '▶',
     *      delete: '🗑'
     *    })
     *    .setFunctionEmojis({
     *      '⬆': (_, instance) => {
     *        for (const embed of instance.array)
     *          embed.fields[0].value++;
     *        },
     *      '⬇': (_, instance) => {
     *         for (const embed of instance.array)
     *           embed.fields[0].value--;
     *        }
     *    })
     *    .setDescription('This is one of my embeds with this message!')
     *    .setColor(0xFF00AE)
     *    .setTimestamp()
     *    .build();```
     */ public async build ( ) { await this . _verify ( ) ; return this . _loadList ( ) ; } param array public setArray ( array ) { const isValidArray = Array . isArray ( array ) && Boolean ( array . length ) ; if ( ! isValidArray ) throw new TypeError ( 'Cannot invoke Embeds class without a valid array to paginate.' ) ; for ( const [ i , v ] of array . entries ( ) ) if ( Boolean ( v ) && v . constructor === Object && Object . keys ( v ) . length ) array [ i ] = new MessageEmbed ( v ) ; else if ( v instanceof MessageEmbed ) continue ; else throw new TypeError ( `(MessageEmbeds[${ i }]) Cannot invoke Embeds class with an invalid MessageEmbed instance.` ) ; this . array = array ; return this ; } param name param iconURL param url public setAuthor ( name , iconURL ? , url ? ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setAuthor ( name , iconURL , url ) ; return this ; } param color public setColor ( color ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setColor ( color ) ; return this ; } param description public setDescription ( description ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setDescription ( description ) ; return this ; } param text param iconURL public setFooter ( text , iconURL ? ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setFooter ( text , iconURL ) ; return this ; } param url public setImage ( url ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setImage ( url ) ; return this ; } param url public setThumbnail ( url ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setThumbnail ( url ) ; return this ; } param timestamp public setTimestamp ( timestamp ? ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setTimestamp ( timestamp ) ; return this ; } param title public setTitle ( title ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setTitle ( title ) ; return this ; } param url public setURL ( url ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . setURL ( url ) ; return this ; } param index param deleteCount param name param value param inline public spliceFields ( index , deleteCount , name ? , value ? , inline ? ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; for ( const el of this . array ) el . spliceFields ( index , deleteCount , [ { name , value , inline } ] ) ; return this ; } /** Transforms all embeds to plain objects. */ public toJSON ( ) { if ( ! this . array ) throw new TypeError ( 'this.array must be set first.' ) ; return this . array . map ( m => m . toJSON ( ) ) ; } ignore public async _loadList ( callNavigation = true ) { if ( this . listenerCount ( 'pageUpdate' ) ) this . emit ( 'pageUpdate' ) ; const embed = new MessageEmbed ( this . currentEmbed ) ; const isFooter = this . usePageIndicator === 'footer' ; const shouldIndicate = this . usePageIndicator && ! isFooter ? this . pages === 1 ? '' : this . pageIndicator : '' ; const { separator , text } = this . content ; const content = `${ text ? `${ text }${ separator }` : '' }${ shouldIndicate }` ; const options = { embeds : [ embed ] , content : content || null } ; if ( isFooter ) embed . setFooter ( this . pageIndicator , embed . footer . iconURL ) ; if ( this . clientAssets . message ) await this . clientAssets . message . edit ( options ) ; else this . clientAssets . message = await this . channel . send ( options ) as Message ; return super . _loadList ( callNavigation ) ; } }