import type { IrcMessage, FormatMessage } from '@tmi.js/irc-parser'; import EventEmitter from './lib/EventEmitter'; import Identity, { type TokenValue } from './lib/Identity'; import Channel, { ChannelPlaceholder } from './lib/Channel'; import * as irc from './irc'; import type { GlobalUserState, Message, Moderation, RoomState, Raid, Subscription, SharedChatNotice, Unraid, UserState, ViewerMilestone, Whisper } from './twitch/events'; export interface ClientOptions { token: TokenValue; channels: string[]; /** * Set the minimum delay between sending join method calls for channels queued with the Client options or after * reconnecting. Defaults to `500` milliseconds. */ joinDelayMs: number; } export type ConnectionEvents = { connect: void; close: { reason: string; code: number; wasCloseCalled: boolean; }; socketError: Event; reconnecting: { attempts: number; waitTime: number; reason: string; }; pong: void; }; export type OtherEvents = { ircMessage: [ircMessage: IrcMessage]; error: [error: Error]; }; declare namespace MessageDropped { interface Event { channel: Channel; reason: 'msg_channel_suspended' | 'msg_banned_phone_number_alias' | 'msg_duplicate' | 'msg_timedout' | 'msg_warned' | 'unrecognized_cmd'; systemMessage: string; tags: irc.NOTICE.Tags; } } export type ChatEvents = { message: Message.Event; messageDropped: MessageDropped.Event; whisper: Whisper.Event; globalUserState: GlobalUserState.Event; userState: UserState.Event; roomState: RoomState.Event; moderation: Moderation.Event; raid: Raid.Event; unraid: Unraid.Event; sub: Subscription.Event; badgeUpgrade: Message.EventBadgeUpgrade; viewerMilestone: ViewerMilestone.Event; sharedChatNotice: SharedChatNotice.Event; join: { channel: Channel; }; part: { channel: Channel; }; }; export type ClientEvents = ConnectionEvents & OtherEvents & ChatEvents; interface Keepalive { maxWaitTimeoutMs: number; /** The timestamp of the last ping received. */ lastPingReceivedAt?: number; /** The timestamp of the last pong received. */ lastPongReceivedAt?: number; /** The timestamp of the last ping sent. */ lastPingSent?: number; /** The latency in milliseconds. */ latencyMs?: number; /** The interval ID for the ping interval. */ pingInterval?: ReturnType; /** The interval in seconds between each ping. */ pingIntervalSeconds: number; /** The timeout ID for the ping timeout. */ pingTimeout?: ReturnType; /** The timeout in seconds for the ping timeout. */ pingTimeoutSeconds: number; /** The amount of reconnect attempts. */ reconnectAttempts: number; /** The timeout ID for the reconnect timeout. */ reconnectTimeout?: ReturnType; /** A function to cancel the current reconnect attempt. Calling this will throw an error for the reconnect caller. */ cancelReconnect?: () => void; } type ToTuples> = { [K in keyof T]: T[K] extends any[] ? T[K] : T[K] extends void ? [] : [event: T[K]]; }; export declare class Client extends EventEmitter> { socket?: WebSocket; readonly keepalive: Keepalive; channelsPendingJoin: Set; pendingChannelJoinDelayMs: number; channels: Set; channelsById: Map; channelsByLogin: Map; identity: Identity; didConnectAnonymously?: boolean; wasCloseCalled: boolean; constructor(opts?: Partial); connect(): void; close(): void; reconnect(reason?: string): Promise; private onSocketMessage; private onSocketClose; private onSocketOpen; private onSocketError; getChannelById(id: string): Channel | undefined; getChannelByLogin(login: string): Channel | undefined; private removeChannel; private clearChannels; getChannelPlaceholder(id?: string, login?: string): ChannelPlaceholder; onIrcLine(line: string): void; onIrcMessage(ircMessage: IrcMessage): void | Promise; private handlePING; private handlePONG; private handlePRIVMSG; private handleUSERSTATE; private handleGLOBALUSERSTATE; private handleUSERNOTICE; private handleNOTICE; private handleCLEARCHAT; private handleCLEARMSG; private handleROOMSTATE; private handlePART; private handleWHISPER; private handleRECONNECT; private handle376; isConnected(): this is { socket: WebSocket & { readyState: typeof WebSocket.OPEN; }; }; send(message: string): void; sendIrc(opts: { channel?: string | Channel; } & Omit): void; join(channelName: string | Channel): Promise; part(channelName: string | Channel): Promise; say(channelName: string | Channel, message: string, tags?: Record): Promise; reply(channelName: string | Channel, message: string, replyParentMsgId: string, tags?: Record): Promise; private generateClientNonce; private ping; private joinPendingChannels; private waitForCommand; } export {};