summaryrefslogtreecommitdiff
path: root/server/src/client
diff options
context:
space:
mode:
author8cy <[email protected]>2020-07-23 23:24:17 -0700
committer8cy <[email protected]>2020-07-23 23:24:17 -0700
commitbb511abc03bb66848947e37a999502b813c77269 (patch)
tree612c010fc8317e1cdf11471a18aad0270819d33e /server/src/client
parentfix: if clear amount equal or over 100, round down to 99 (diff)
downloaddep-core-bb511abc03bb66848947e37a999502b813c77269.tar.xz
dep-core-bb511abc03bb66848947e37a999502b813c77269.zip
goodbye old uwufier :cry:
Diffstat (limited to 'server/src/client')
-rw-r--r--server/src/client/BotClient.ts103
1 files changed, 103 insertions, 0 deletions
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<string> => {
+ 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<this> {
+ 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<string> {
+ await this.init();
+ return this.login(this.config.token);
+ }
+} \ No newline at end of file