import { Client } from 'eris'; import { Config, Logger, Redis } from './Helpers'; import { CommandHandler, EventHandler, RunnerHandler, PermissionHandler } from './Handlers'; import { Parser } from './Modules'; import { Collection } from './Util'; import * as path from 'path'; import * as Sentry from '@sentry/node'; export class ZenithClient extends Client { private readonly _token: string; public botdir: string; public configfile: string; public prefix: string; public client: Client; private config: Config; public sentry; public redis: Redis; public parser: Parser; public commands: CommandHandler; public events: EventHandler; public runners: RunnerHandler; public permissions: PermissionHandler; private moduleHandlers: Collection; public dir: any; constructor(options) { super(options.token, options.clientOptions); this.config = new Config(); if (this.config.get('sentry.dsn', null) !== null) { this.sentry = Sentry.init({ dsn: this.config.get('sentry.dsn', undefined) }); } this.botdir = options.botdir; this.configfile = options.configfile; this.prefix = this.config.get('prefix', '>>'); this._token = options.token; this.dir = `${options.clientOptions.dir}/`; this.redis = new Redis(this); this.commands = new CommandHandler(this); this.events = new EventHandler(this); this.runners = new RunnerHandler(this); this.permissions = new PermissionHandler(this); this.moduleHandlers = new Collection(); this.client = new Client(this._token); this.parser = new Parser(this); } registerHandler(handler) { this.moduleHandlers.set(handler.name, handler); return this; } public async register(): Promise < void > { const Log = new Logger('Client'); Log.info('Registering modules..'); this.registerHandler(this.commands); this.registerHandler(this.events); this.registerHandler(this.runners); this.registerHandler(this.permissions); const coreDir = path.join(__dirname, '../'); for (const handler of this.moduleHandlers.values()) { await handler.registeruserDirs(this.dir); await handler.registercoreDirs(coreDir); } } public async start(): Promise < void > { const Log = new Logger('Client'); Log.info('Starting Zenith!'); await this.register(); await Promise.all(this.moduleHandlers.map(async handler => await handler.loadAll())) .catch(err => { Log.error(err); process.exit(); }); await this.connect().catch(err => { Log.error(err); }); } }