import { AkairoClient, CommandHandler, ListenerHandler, InhibitorHandler } from 'discord-akairo'; import { Message } from 'discord.js'; import { join } from 'path'; import { prefix, owners } from '../Config'; import { logger } from '../utils/Logger'; import { SettingsProvider } from '../database'; import { Logger } from 'winston'; import svg2img from 'svg2img'; declare module 'discord-akairo' { interface AkairoClient { commandHandler: CommandHandler; listenerHandler: ListenerHandler; logger: Logger; settings: SettingsProvider; img, wait } } interface BotOptions { token?: string; owners?: string[]; // prefix?: string; } export default class BotClient extends AkairoClient { public readonly config: BotOptions; public logger = logger; public img = (data) => { return new Promise((resolve, reject) => { svg2img(data, (error, buffer) => { return resolve(buffer); }); }); } public wait = require("util").promisify(setTimeout); public inhibitorHandler: InhibitorHandler = new InhibitorHandler(this, { directory: join(__dirname, '..', 'inhibitors') }); public listenerHandler: ListenerHandler = new ListenerHandler(this, { directory: join(__dirname, '..', 'listeners') }); public commandHandler: CommandHandler = new CommandHandler(this, { directory: join(__dirname, '..', 'commands'), /* prefix: async (msg: Message): Promise => { if (msg.guild) { const doc = this.settings.cache.guilds.get(msg.guild.id); if (doc?.prefix) return doc.prefix; } return this.config.prefix }, */ prefix, allowMention: true, defaultCooldown: 6e4, // 60000 - 6 - count the zeroes... = 4, so its 6e4 ignorePermissions: owners, // Extra stuff argumentDefaults: { prompt: { modifyStart: (_: Message, str: string): string => `${str}\n\nType \`cancel\` to cancel the command...`, modifyRetry: (_: Message, str: string): string => `${str}\n\nType \`cancel\` to cancel the command...`, timeout: 'You took too long, the command has now been cancelled...', ended: 'You exceeded the maximum amount of tries, this command has now been cancelled...', cancel: 'This command has been cancelled...', retries: 3, time: 3e4 }, otherwise: '' } }); public settings: SettingsProvider = new SettingsProvider(this); public constructor(config: BotOptions) { super({ ownerID: config.owners, messageCacheMaxSize: 50, messageSweepInterval: 900, messageCacheLifetime: 300, partials: ['MESSAGE', 'REACTION'] }); this.config = config; this.on('shardError', (err: Error, id: any): Logger => this.logger.warn(`[SHARD ${id} ERROR] ${err.message}`, err.stack)) .on('warn', (warn: any): Logger => this.logger.warn(`[CLIENT WARN] ${warn}`)); } private async init(): Promise { await this.settings.init(); this.commandHandler.useInhibitorHandler(this.inhibitorHandler); this.commandHandler.useListenerHandler(this.listenerHandler); this.listenerHandler.setEmitters({ commandHandler: this.commandHandler, listenerHandler: this.listenerHandler, inhibitorHandler: this.inhibitorHandler, process }); this.commandHandler.loadAll(); this.listenerHandler.loadAll(); this.inhibitorHandler.loadAll(); return this; } public async start(): Promise { await this.init(); return this.login(this.config.token); } }