From bb511abc03bb66848947e37a999502b813c77269 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Thu, 23 Jul 2020 23:24:17 -0700 Subject: goodbye old uwufier :cry: --- server/src/client/BotClient.ts | 103 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 server/src/client/BotClient.ts (limited to 'server/src/client/BotClient.ts') diff --git a/server/src/client/BotClient.ts b/server/src/client/BotClient.ts new file mode 100644 index 0000000..da23a7b --- /dev/null +++ b/server/src/client/BotClient.ts @@ -0,0 +1,103 @@ +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'; + +declare module 'discord-akairo' { + interface AkairoClient { + commandHandler: CommandHandler; + listenerHandler: ListenerHandler; + logger: Logger; + settings: SettingsProvider; + } +} + +interface BotOptions { + token?: string; + owners?: string[]; + // prefix?: string; +} + +export default class BotClient extends AkairoClient { + public readonly config: BotOptions; + + public logger = logger; + + 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); + } +} \ No newline at end of file -- cgit v1.2.3