@twitchfy/chatbot
Version:
A powerful node module to make your own Twitch ChatBot
177 lines (176 loc) • 6.54 kB
TypeScript
import type { GetClipsOptions, GetStreamsOptions } from '@twitchfy/helix';
import { HelixClient } from '@twitchfy/helix';
import { BaseChannel } from './BaseChannel';
import { Collection } from './Collection';
import { ChatBotUser } from './ChatBotUser';
import type { ChatCommand } from './ChatCommand';
import type { TwitchContext } from './TwitchContext';
import type { ChannelProfile } from './ChannelProfile';
import { Stream } from './Stream';
import { Clip } from './Clip';
import { ChatBotChatterManager } from './managers';
import { ChatBotWarnsManager } from './managers';
import { ChannelManager, ChatBotBanManager, ChatBotMessageManager, ChatBotTimeoutManager, ChatBotUserManager } from './managers';
import { EventSubConnection } from '../enums';
import type { Events as ChatBotEvents } from '../types';
import type { ChatBotOptions, EventSubConnectionMap } from '../interfaces';
import type { EventDataForConnection } from '../functions';
/**
* Represents a chatbot.
*/
export declare class ChatBot<T extends EventSubConnection = EventSubConnection> {
/**
* The client Id of the Twitch's application.
*/
readonly clientId: string;
/**
* The client secret of the Twitch's application.
*/
readonly clientSecret: string;
/**
* A Collection of the profiles of the joined channels.
*/
readonly profiles: Collection<string, ChannelProfile<T>>;
/**
* The manager of the chatbot channels.
*/
readonly channels: ChannelManager<T>;
/**
* The handlers of resources of the chatbot.
* @private
*/
private readonly handlers;
/**
* A Collection of the chatbot commands.
*/
readonly commands: Collection<string, ChatCommand<T>>;
/**
* A Collection of the chatbot events.
*/
readonly events: Collection<ChatBotEvents, EventDataForConnection<T>[keyof EventDataForConnection<T>]>;
/**
* The message manager of the chatbot.
*/
readonly messages: ChatBotMessageManager<T>;
/**
* The ban manager of the chatbot.
*/
readonly bans: ChatBotBanManager<T>;
/**
* The user manager of the chatbot.
*/
readonly users: ChatBotUserManager<T>;
/**
* The timeout manager of the chatbot.
*/
readonly timeouts: ChatBotTimeoutManager<T>;
/**
* The warning manager of the chatbot.
*/
readonly warns: ChatBotWarnsManager<T>;
/**
* The chatters manager of the chatbot.
*/
readonly chatters: ChatBotChatterManager<T>;
/**
* The Twitch user of the chatbot.
*/
user: ChatBotUser<T>;
/**
* The user Id of the chatbot.
*/
userId: string;
/**
* The operator to separate the options in the command.
*/
readonly optionOperator: string;
/**
* The EventSub connection type used by the chatbot.
*/
readonly connectionType: T;
/**
* The EventSub connection of the chatbot.
*/
readonly eventsub: EventSubConnectionMap[T];
/**
* The Helix client of the chatbot.
*/
readonly helixClient: HelixClient;
/**
* The options of the chatbot.
*/
readonly options: ChatBotOptions<T>;
/**
* The prefix callback used to handle command prefixes.
* @protected
*/
protected __prefix: (message: TwitchContext<{}, T>) => string[];
/**
* Creates a new instance of the chatbot.
* @param options The options to build up the chatbot.
*/
constructor(options: ChatBotOptions<T>);
/**
* Creates the EventSub connection of the chatbot.
* @param type The type of the EventSub connection.
* @param options The options to build up the EventSub connection.
* @returns The EventSub connection of the chatbot.
* @private
*/
private createEventSubConnection;
/**
* Start the chatbot.
* @param options The start options to start the chatbot.
* @returns The current instance of the chatbot. When the promise is resolved the chatbot has been completly started.
*/
start(options?: StartOptions<T>): Promise<this>;
streams(): Promise<Stream<T>[] | null>;
streams(number?: number): Promise<Stream<T>[] | null>;
streams(options: GetStreamsOptions<true>, number?: number): Promise<Stream<T>[] | null>;
/**
* Fetches a Twitch stream from the API.
* @param options The options for filter the stream.
* @returns A stream fetched from the API or null if the stream wasn't founded.
*/
stream(options: GetStreamsOptions<false>): Promise<Stream<T> | null>;
/**
* Get Twitch clips from the API.
* @param options The options to filter the clips.
* @returns An array containing the clips fetched from the API. If there isn't any clip founded, it will return a nullish value.
*/
clips(options: GetClipsOptions<true>): Promise<Clip<T>[] | null>;
/**
* Get a specific Twitch clip from the API.
* @param options The options to filter the clip.
* @returns The clip fetched from the API or null if the clip wasn't founded.
*/
clip(options: GetClipsOptions<false>): Promise<Clip<T> | null>;
/**
* Checks whether the chatbot is moderator in a specific channel.
* @param channelId The Id of the channel to check.
* @returns A boolean indicating whether the chatbot is moderator in the channel.
*/
isModerator(channelId: string): Promise<boolean>;
/**
* Get the moderated channels of the chatbot.
* @returns An array containing the moderated channels of the chatbot.
*/
moderatedChannels(): Promise<BaseChannel<T>[]>;
/**
* The user token of the chatbot Twitch account to make requests.
*/
get userToken(): import("@twitchfy/helix").UserTokenAdapter<boolean> | undefined;
/**
* The app token of the Twitch application. The value is null if the chatbot is using a WebSocket EventSub connection.
*/
get appToken(): import("@twitchfy/eventsub").TokenAdapter<"app", boolean> | null;
}
/**
* The options to start the chatbot.
* @param port The port to start the express server if the startServer option is set into true. Only required if the chatbot is using a Webhook EventSub connection.
* @param callback A callback to execute when the chatbot is started. Only required if the chatbot is using a Webhook EventSub connection.
*/
export type StartOptions<T extends EventSubConnection> = T extends EventSubConnection.Webhook ? {
port?: number;
callback?: () => void;
} : {};