tangled
alpha
login
or
join now
thevoid.cafe
/
voidy
0
fork
atom
A powerful and extendable Discord bot, with it's own module system :3
thevoid.cafe/projects/voidy
0
fork
atom
overview
issues
pulls
pipelines
✨ Add FeatureHandler for larger systems
Jo
1 year ago
70a0b1f6
5ddb29f3
+52
4 changed files
expand all
collapse all
unified
split
src
features
chatbot
feature.json
handlers
FeatureHandler.ts
utils
classes
Feature.ts
VoidyClient.ts
+4
src/features/chatbot/feature.json
···
1
1
+
{
2
2
+
"name": "chatbot",
3
3
+
"version": "0.1.0"
4
4
+
}
+31
src/handlers/FeatureHandler.ts
···
1
1
+
import { walk } from "https://deno.land/std@0.170.0/fs/walk.ts";
2
2
+
import { VoidyClient } from "../utils/classes/VoidyClient.ts";
3
3
+
import { Feature, FeatureOptions } from "../utils/classes/Feature.ts";
4
4
+
import { CommandHandler } from "./CommandHandler.ts";
5
5
+
import { EventHandler } from "./EventHandler.ts";
6
6
+
7
7
+
export class FeatureHandler {
8
8
+
public static async loadAll(client: VoidyClient, paths: string[] = []) {
9
9
+
for (const path of paths) {
10
10
+
await this.handleDirectory(client, path);
11
11
+
}
12
12
+
13
13
+
console.log();
14
14
+
}
15
15
+
16
16
+
protected static async handleDirectory(client: VoidyClient, path: string) {
17
17
+
console.log(`[Voidy] Loading Features from: ${path}`);
18
18
+
console.log();
19
19
+
20
20
+
for await (const walkEntry of walk(path)) {
21
21
+
if (!walkEntry.isFile || walkEntry.name !== "feature.json") continue;
22
22
+
23
23
+
const featureDirectory = walkEntry.path.split("/feature.json")[0];
24
24
+
const feature = (await import(`file://${Deno.cwd()}/${walkEntry.path}`, { with: { type: "json" } })).default as FeatureOptions;
25
25
+
client.features.set(feature.name, new Feature(feature));
26
26
+
27
27
+
await CommandHandler.loadCommands(client, [`${featureDirectory}/commands`]);
28
28
+
await EventHandler.loadEvents(client, [`${featureDirectory}/events`]);
29
29
+
}
30
30
+
}
31
31
+
}
+14
src/utils/classes/Feature.ts
···
1
1
+
export class Feature {
2
2
+
constructor(options: FeatureOptions) {
3
3
+
this.name = options.name;
4
4
+
this.version = options.version;
5
5
+
}
6
6
+
7
7
+
public name: string;
8
8
+
public version: string;
9
9
+
}
10
10
+
11
11
+
export interface FeatureOptions {
12
12
+
name: string,
13
13
+
version: string,
14
14
+
}
+3
src/utils/classes/VoidyClient.ts
···
1
1
import { Client, ClientOptions, Collection } from "discord.js";
2
2
import { Command } from "./Command.ts";
3
3
+
import { Feature } from "./Feature.ts";
3
4
4
5
export class VoidyClient extends Client {
5
6
constructor(options: ClientOptions) {
···
7
8
8
9
this.commands = new Collection<string, Command>();
9
10
this.events = new Collection<string, string>();
11
11
+
this.features = new Collection<string, Feature>();
10
12
}
11
13
12
14
public commands: Collection<string, Command>;
13
15
public events: Collection<string, string>;
16
16
+
public features: Collection<string, Feature>
14
17
}