blob: d3b39e0face9a59b5b55476b8adeb4b2f2ddf76c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import { Message, GuildMember, Guild, User } from "discord.js";
import fs from "fs";
export type CommandContext = {
user: User,
guild: Guild | null,
member: GuildMember | null,
message: Message,
args: string[],
};
export type Command = {
name: string;
exec: (ctx: CommandContext) => any;
};
const walk = async (path: string) => {
const files = fs.readdirSync(path);
const out = [];
for (var file of files) {
if (fs.statSync(`${path}/${file}`).isDirectory()) continue;
if (file.indexOf("index") !== -1)
continue;
if (file.indexOf(".js") !== file.length - 3) continue;
var imported = (await import(`./${file}`)).default;
out.push(imported);
}
return out;
};
export const getCommands = async () => {
const map: { [key: string]: Command } = {};
for (var cmd of await walk("./build/commands")) {
map[cmd.name] = cmd;
}
return map;
};
|