summary refs log tree commit diff
path: root/slowcord/bot/src/commands/index.ts
blob: ef2d2a22e0437eeee86226e056596149c1f8a480 (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
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): Promise<Command[]> => {
	const files = fs.readdirSync(path);
	const out: Command[] = [];
	for (var file of files) {
		if (file.indexOf("index") !== -1) continue;

		var imported = await import(`${path}/${file}`);
	}

	return out;
};

export const getCommands = async () => {
	const map: { [key: string]: Command; } = {};
	(await walk("./build/commands")).forEach((val) => map[val.name] = val);
	return map;
};