UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

125 lines (124 loc) 2.97 kB
/** * A strategy for posting messages to Discord. */ export class DiscordStrategy { /** * Creates a new instance. * @param {DiscordOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: DiscordOptions); /** * Maximum length of a Discord message in characters. * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Calculates the length of a message according to Discord's algorithm. * All characters are counted as is. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; /** * Posts a message to Discord. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<DiscordMessageResponse>} A promise that resolves with the message data. * @throws {Error} When the message fails to post. */ post(message: string, postOptions?: PostOptions): Promise<DiscordMessageResponse>; #private; } export type PostOptions = import("../types.js").PostOptions; export type DiscordOptions = { /** * The Discord bot token. */ botToken: string; /** * The Discord channel ID to post to. */ channelId: string; }; export type DiscordMessageResponse = { /** * The ID of the created message. */ id: string; /** * The ID of the channel the message was posted to. */ channel_id: string; /** * The content of the message. */ content: string; }; export type DiscordErrorResponse = { /** * The error code. */ code: number; /** * The error message. */ message: string; }; export type DiscordPayload = { /** * The text content of the message */ content: string; /** * Array of embedded messages */ embeds?: DiscordEmbed[] | undefined; /** * Array of file attachments */ attachments?: DiscordAttachment[] | undefined; }; export type DiscordEmbedImage = { /** * URL of the image */ url: string; }; export type DiscordEmbed = { /** * The description of the embed */ description?: string | undefined; /** * The main image */ image?: DiscordEmbedImage | undefined; }; export type DiscordAttachment = { /** * The unique identifier for the attachment */ id: number; /** * A description of the attachment */ description: string; /** * The filename of the attachment */ filename: string; };