UNPKG

@oceanicjs/builders

Version:

Helpful builders for various Discord related things.

126 lines (125 loc) 5.3 kB
import Button from "./Structures/Button"; import SelectMenu from "./Structures/SelectMenu"; import TextInput from "./Structures/TextInput"; import type { ButtonColors } from "./Constants"; import { ButtonStyles, MessageActionRow, ModalActionRow, PartialEmoji, RawMessageActionRow, RawModalActionRow, SelectMenuTypes, SelectOption, TextInputStyles } from "oceanic.js"; type RowMax = 1 | 2 | 3 | 4 | 5; type ValidComponents = Button | SelectMenu | TextInput; type ToRaw<T extends MessageActionRow | ModalActionRow> = T extends MessageActionRow ? RawMessageActionRow : RawModalActionRow; export default class ComponentBuilder<T extends MessageActionRow | ModalActionRow = MessageActionRow | ModalActionRow> { private currentIndex; private rows; rowMax: RowMax; constructor(rowMax?: RowMax); /** * Convert an emoji to a partial. * @param emoji The unicode point of the emoji if default, else the fully qualified emoji. * @param type `default` if built in (unicode), `custom` otherwise (this can be assumed from the format by us). * @example emojiToPartial("🐾", "default") * @example emojiToPartial("<:paws8:681748079778463796>", "custom") */ static emojiToPartial(emoji: string, type?: "default" | "custom"): PartialEmoji; private getCurrentRow; /** * Add a component to the current row, or a new row depending on certain conditions * @param component The component to add. */ addComponent(component: ValidComponents): this; /** * Add several components. * @param components The components to add. */ addComponents(...components: Array<ValidComponents>): this; /** * Add an interaction button to the current row. * @param options The options for adding the interaction button. */ addInteractionButton(options: AddInteractionButtonOptions): this; /** * Start a new action row. * @param components The components to start this new row with. */ addRow(components?: Array<ValidComponents>): this; /** * Add a select menu (to the current row, if empty - else as a new row). * @param options The options for adding the select menu. */ addSelectMenu(options: AddSelectMenuOptions): this; /** * Add a text input to the current row. * @param options The options for adding the text input. * @returns */ addTextInput(options: AddTextMenuOptions): this; /** * Add a url button to the current row * @param options The options for adding the url button. */ addURLButton(options: AddURLButtonOptions): this; /** * Remove all of the rows that are empty. */ removeEmptyRows(): this; setRowMax(rowMax: RowMax): this; /** convert the current contents to JSON */ toJSON(): Array<T>; /** convert the current contents to JSON */ toJSONRaw(): Array<ToRaw<T>>; } export interface AddInteractionButtonOptions { /** A developer-defined identifier for the button, max 100 characters. */ customID: string; /** If the button is disabled. */ disabled?: boolean; /** An emoji that appears on the button. */ emoji?: PartialEmoji; /** Text that appears on the button, max 80 characters. */ label?: string; /** The [style](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles) of the button. */ style: ButtonStyles | ButtonColors; } export interface AddSelectMenuOptions { /** A developer-defined identifier for the button, max 100 characters. */ customID: string; /** Disable the select, default false. */ disabled?: boolean; /** The maximum number of items that can be chosen; default 1, max 25. */ maxValues?: number; /** The minimum number of items that must be chosen; default 1, min 0, max 25. */ minValues?: number; /** The choices in the select, max 25. */ options: Array<SelectOption>; /** Custom placeholder text if nothing is selected, max 100 characters. */ placeholder?: string; /** The type of select menu to add. */ type: SelectMenuTypes; } export interface AddTextMenuOptions { /** A developer-defined identifier for the input, max 100 characters. */ customID: string; /** The label for this text input. */ label: string; /** The maximum input length for a text input, min 1, max 4000. */ maxLength?: number; /** The minimum input length for a text input, min 0, max 4000. */ minLength?: number; /** Custom placeholder text if the input is empty, max 100 characters. */ placeholder?: string; /** If this component is required to be filled, default true. */ required?: boolean; /** The [style](https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles) of the text input. */ style: TextInputStyles; /** A pre-filled value for this component, max 4000 characters. */ value?: string; } export interface AddURLButtonOptions { /** If the button is disabled. */ disabled?: boolean; /** An emoji that appears on the button. */ emoji?: PartialEmoji; /** Text that appears on the button, max 80 characters. */ label?: string; /** The url to open when clicked. */ url: string; } export {};