Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import { EventEmitter } from 'node:events';
import type { Platform } from './types';
import { LogLevel, Logger } from './logger';
import { FlarieCommand } from './types/command';
export class Flarie extends EventEmitter {
#options: Flarie.InternalOptions;
constructor({ commands, level, ...options }: Flarie.Options) {
super();
if (level) Logger.setLevel(level);
this.#options = options;
const promises: Promise<void>[] = [];
promises.push(
this.#options.platform.authenticate().then(async () => {
Logger.info('Successfully authenticated with platform.');
if (commands) {
await this.#register(commands);
}
})
);
promises.push(new Promise((resolve) => this.#options.platform.once('ready', () => resolve())));
Promise.all(promises)
.then(() => this.emit('ready'))
.catch((errors) => this.emit('error', errors));
}
async #register(commands: FlarieCommand[]): Promise<void> {
Logger.silly('Registering commands with platform...');
await this.#options.platform.register(commands);
Logger.info('Successfully registered commands with platform.');
}
async send(serverId: string, channelId: string, message: string): Promise<void> {
await this.#options.platform.send(serverId, channelId, message);
}
}
export namespace Flarie {
export type Options = {
platform: Platform;
commands?: FlarieCommand[];
level?: LogLevel;
};
export type InternalOptions = {
platform: Platform;
};
}
export { Logger, LogLevel };
export { CampfirePlatform } from './campfire';
export { FlarieCommand } from './types/command';
export * from './types';
|