UNPKG

@ayanaware/bentocord

Version:

Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.

60 lines (59 loc) 2.54 kB
import { FileContent } from 'eris'; import type { AnyContext } from '../contexts/AnyContext'; import type { AgnosticMessageContent } from '../interfaces/AgnosticMessageContent'; import type { ComponentsManager } from './ComponentsManager'; import type { AnyComponentContext } from './contexts/AnyComponentContext'; import type { Button } from './helpers/Button'; import type { Select } from './helpers/Select'; export declare type AnyComponent = Button | Select; export declare type ContentTransformer = (content?: AgnosticMessageContent) => Promise<AgnosticMessageContent>; export declare class ComponentOperation<T = void> { protected readonly ctx: AnyContext; protected readonly cm: ComponentsManager; protected isClosing: boolean; protected _content: AgnosticMessageContent; protected _merge: AgnosticMessageContent; transformer: ContentTransformer; protected _files: Array<FileContent>; protected _rows: Array<Array<AnyComponent>>; readonly maxRowCount = 5; timeoutSeconds: number; private timeout; private messageId; protected resolve: (value?: T) => void; protected reject: (reason?: any) => void; constructor(ctx: AnyContext); content(content: string | AgnosticMessageContent): this; contentTranslated(key: string, repl?: Record<string, unknown>, backup?: string): Promise<this>; files(files: Array<FileContent>): this; clearRows(): this; setRows(rows: Array<Array<AnyComponent>>): this; setRow(n: number, row: Array<AnyComponent>): this; addRows(rows: Array<Array<AnyComponent>>): this; addRow(row: Array<AnyComponent>): this; /** * A helper function to help build more complex/dynamic operations * Some examples would be a button that re-renders itself etc */ update(): Promise<void>; draw(): Promise<void>; /** * Merge & build the final message content object */ build(): Promise<AgnosticMessageContent>; /** * Actually "writes/makes visible" the state of this operation to the user. * When overriding this function take care that you always super.render(); */ render(): Promise<void>; protected handleInteraction(ctx: AnyComponentContext): Promise<void>; protected refreshTimeout(): void; protected handleTimeout(): Promise<void>; /** * Promise won't resolve until the ComponentMessage is closed * Can be used to block further execution */ start(): Promise<T>; close(reason?: unknown): Promise<void>; cleanup(): Promise<void>; }