import { Connection } from '../skychat/Connection.js'; import { Room } from '../skychat/Room.js'; import { Session } from '../skychat/Session.js'; import { User } from '../skychat/User.js'; /** * Plugin command parameters description object */ export type PluginCommandRules = { /** * Minimum number of expected parameters */ minCount?: number; /** * Maximum number of parameters */ maxCount?: number; /** * Minimum duration between two consecutive calls */ coolDown?: number; /** * Maximum number of time this function can be called within a 10 second window */ maxCallsPer10Seconds?: number; /** * Cost of each call per right level */ callCostPerRight?: [number, number][]; /** * Expected parameters */ params?: { name: string; pattern: RegExp; info?: string; }[]; }; export type PluginCommandAllRules = Record; /** * Abstract class that represents a plugin. A plugin has access to multiple points of the application through the usage * of hooks. Every room has its own instance of plugin. A plugin can also save data to persistent storage. */ export declare abstract class Plugin { /** * Base path for plugin persistent storage */ static readonly STORAGE_BASE_PATH: string; /** * Helper regexp used by sub classes */ static readonly POSITIVE_INTEGER_REGEXP: RegExp; /** * Some plugins (i.e. plugin to ban users) are globally available. * They have a single storage file, and they are instantiated only once at the root-level instead of once per room. * This static attribute need to be set * @abstract */ static readonly isGlobal: boolean; /** * Plugin command name */ static readonly commandName: string; /** * Plugin command aliases */ static readonly commandAliases: string[]; /** * If the plugin uses user storage, it needs to define a default value for its custom entry in user data object. */ static readonly defaultDataStorageValue?: any; /** * Define command rules, ie expected parameters and cooldown. Can be defined globally or per command alias. */ readonly rules: PluginCommandAllRules; /** * Minimum right to execute this function */ readonly minRight: number; /** * Is the command reserved for op */ readonly opOnly?: boolean; /** * Whether this command can be invoked using /{alias} */ readonly callable: boolean; /** * Whether this command should be hidden from the /help */ readonly hidden: boolean; /** * Limiters for this plugin */ private readonly limiters; /** * This plugin's persistent storage */ protected storage: any; /** * Save this plugin's data to the disk */ protected syncStorage(): void; /** * Save this plugin's data to the disk */ protected loadStorage(): void; /** * Get command name */ get commandName(): string; /** * Get this plugin's storage path. * Path differ depending on whether the plugin is global or per-room. * @abstract */ abstract getStoragePath(): string; /** * Load user data for this plugin */ getUserData(user: User): T; /** * Save user data for this plugin */ saveUserData(user: User, data: any): Promise; /** * Check command rights and arguments */ check(alias: string, param: string, connection: Connection): Promise; /** * Execute the command * @param alias * @param param * @param connection */ execute(alias: string, param: string, connection: Connection): Promise; /** * Plugin implementation */ abstract run(alias: string, param: string, connection: Connection, session: Session, user: User, room: Room | null): Promise; /** * When binary data is received * @abstract * @param _connection * @param _messageType * @param _data * @returns Whether the data was handled. If returning true, no other plugin will be able to handle binary data. */ onBinaryDataReceived(_connection: Connection, _messageType: number, _data: Buffer): Promise; }