thaldrin/src/handler/client/Client.ts

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-04-04 15:17:46 +00:00
import { Client, Collection } from "discord.js";
import { readdirSync as read } from "fs";
import path from "path";
2021-05-05 12:57:42 +00:00
import { Command } from "../../utils/types";
2021-04-21 00:28:07 +00:00
import Logger from "../../utils/logger";
// import { Prom } from "../../utils/prometheus";
2021-04-04 15:17:46 +00:00
// const server = require('../../website/server');
export default class Thaldrin extends Client {
2021-05-05 12:57:42 +00:00
commands: Collection<string, Command>;
2021-04-04 15:17:46 +00:00
cooldowns: Collection<unknown, unknown>;
config: any;
lastEval: any;
2021-04-28 01:32:07 +00:00
constructor(config: { token: any; }) {
2021-04-04 15:17:46 +00:00
super({
// disableEveryone: true,
2021-04-28 01:32:07 +00:00
// disabledEvents: ['TYPING_START'],
// shardCount: shards,
2021-04-04 15:17:46 +00:00
// totalShardCount: shards
});
this.commands = new Collection();
this.cooldowns = new Collection();
// this.queues = new Collection();
this.config = config;
this.lastEval = null;
2021-07-08 11:49:00 +00:00
// @ts-ignore
// this.on("raw", packet => {
// Prom.events.labels(packet.t).inc()
// })
2021-04-04 15:17:46 +00:00
this.login(config.token);
this.load();
}
async load() {
const events = await read(path.join(__dirname, '../../events'));
const modules = await read(path.join(__dirname, '../../modules'));
// server(this);
events.filter((f) => f.endsWith('.js')).forEach((file) => {
try {
const event = require(path.join(__dirname, '../../events', file));
this.on(event.name, event.run.bind(null, this));
} catch (err) {
console.error(err);
}
});
modules.filter((f) => !f.endsWith('.js')).forEach(async (module) => {
const commands = await read(path.join(__dirname, '../../modules', module));
commands.filter((f) => f.endsWith('.js')).forEach((command) => {
try {
const file = require(path.join(__dirname, '../../modules', module, command));
const Command = new file();
Command.module = module
2021-04-22 01:33:59 +00:00
// Logger.info({
// type: "command:loaded",
// command: Command.name,
2021-05-06 20:14:34 +00:00
// message: `${Command.name}:${Command.module} was loaded`
2021-04-22 01:33:59 +00:00
// })
2021-04-04 15:17:46 +00:00
this.commands.set(Command.name, Command);
} catch (err) {
console.error(err);
}
});
});
}
};