UNPKG

@oceanicjs/builders

Version:

Helpful builders for various Discord related things.

182 lines (181 loc) 5.18 kB
import { EmbedAuthorOptions, EmbedField, EmbedFooterOptions, EmbedImageOptions, EmbedOptions, RawEmbedOptions } from "oceanic.js"; export default class EmbedBuilder { private json; /** * create an embed builder instance (or multiple) from the provided json * @param json - the embed json - accepts singular & array * @param forceSingular - force a singular return when an array is supplied */ static loadFromJSON(json: EmbedOptions): EmbedBuilder; static loadFromJSON<T extends boolean = false>(json: Array<EmbedOptions>, forceSingular?: T): T extends true ? EmbedBuilder : Array<EmbedBuilder>; /** * load json into this embed builder instance - use static loadFromJSON method * @private * @param {EmbedOptions} json - the json to load * @returns {this} */ private load; /** * Add a blank field to the embed (zero width spaces). * @param inline If the field should be displayed inline. */ addBlankField(inline?: boolean): this; /** * Add a field to the embed. * @param name The field name. * @param value The field value. * @param inline If the field should be inline. */ addField(name: string, value: string, inline?: boolean): this; /** * Add multiple fields. * @param fields The fields to add. */ addFields(...fields: Array<EmbedField | Array<EmbedField>>): this; /** * Get the current author. */ getAuthor(): EmbedAuthorOptions | undefined; /** * Get the current color. */ getColor(): number | undefined; /** * Get the current description. */ getDescription(): string | undefined; /** * Get the field at the specified index. * @param index The index of the field to get. */ getField(index: number): EmbedField | undefined; /** * Get the current fields. */ getFields(): Array<EmbedField>; /** * Get the current footer. */ getFooter(): EmbedFooterOptions | undefined; /** * Get the current image. */ getImage(): EmbedImageOptions | undefined; /** * Get the current thumbnail. */ getThumbnail(): EmbedImageOptions | undefined; /** * Get the current timestamp. */ getTimestamp(): string | undefined; /** * Get the current timestamp as a date instance. */ getTimestampDate(): Date | undefined; /** * Get the current title. */ getTitle(): string | undefined; /** * Get the current url. */ getURL(): string | undefined; /** * remove the current author * @returns {this} */ removeAuthor(): this; /** * Remove the current color. */ removeColor(): this; /** * Remove the current description. */ removeDescription(): this; /** * Remove the current footer. */ removeFooter(): this; /** * Remove the current image. */ removeImage(): this; /** * Remove the current thumbnail. */ removeThumbnail(): this; /** * Remove the current timestamp. */ removeTimestamp(): this; /** * Remove the current title. */ removeTitle(): this; /** * Remove the current url. */ removeURL(): this; /** * set the embed author * @param name The name of the author. * @param iconURL An icon url for the author. * @param url A url for the author. */ setAuthor(name: string, iconURL?: string, url?: string): this; /** * Set the embed color. * @param color The color. */ setColor(color: number): this; /** * Set the embed description. * @param value The description. A string, array of strings, or both spread across multiple parameters. They will be joined by LF charactes. */ setDescription(first: string | Array<string>, ...other: Array<(string | Array<string>)>): this; /** * Set the embed footer. * @param text - The text. * @param iconURL - The icon url. */ setFooter(text: string, iconURL?: string): this; /** * Set the embed image. * @param url The Image url. */ setImage(url: string): this; /** * Set the embed thumbnail. * @param url The thumbnail url. */ setThumbnail(url: string): this; /** * Set the embed timestamp. * @param time An ISO 8601 timestamp, Date object, or "now". */ setTimestamp(time: string | Date | "now"): this; /** * Set the embed title. * @param title The title. */ setTitle(title: string): this; /** * Set the embed url. * @param url The url. */ setURL(url: string): this; /** * Convert this embed to a json object. * @param array If the returned value should be contained in an array. */ toJSON(array: true): [EmbedOptions]; toJSON(array?: false): EmbedOptions; /** * Convert this embed to a raw json object. * @param array If the returned value should be contained in an array. */ toJSONRaw(array: true): [RawEmbedOptions]; toJSONRaw(array?: false): RawEmbedOptions; }