Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 07a392d

Browse files
committed
t
1 parent bd02251 commit 07a392d

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

src/deploy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
class SlashCommands {
4+
5+
}

src/events/ready.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export default class ReadyEvent implements GatewayEvent {
66
once: boolean = true;
77

88
async code (kogBot: KOGBot, client: Client) {
9+
const debug = kogBot.debug;
10+
911
await client.user?.setPresence({
10-
status: "idle",
12+
status: debug ? 'dnd' : 'online',
1113
activities: [{
12-
name: "with your mom",
13-
type: ActivityType.Playing
14+
name: debug ? 'debug mode ⚠️' : 'with Knex.',
15+
type: debug ? ActivityType.Competing : ActivityType.Playing
1416
}]
1517
})
1618
}

src/index.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import knex, { Knex } from "knex";
44
import toml from 'toml';
55
import * as Sentry from '@sentry/node';
66
import { nodeProfilingIntegration } from "@sentry/profiling-node";
7+
import { join } from "path";
8+
import url from "url";
9+
import { readdirSync } from "fs";
10+
11+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
712

813
class DBot extends Client {
914
kogBot: KOGBot;
@@ -22,17 +27,50 @@ class DBot extends Client {
2227
this.REST.setToken(this.kogBot.environment.discord.client_token);
2328

2429
if (!kogBot.ci_workflow) {
30+
this.gatewayEvents.listen().then(() => console.log("Listening to events."));
2531
this.login(this.kogBot.environment.discord.client_token);
32+
}
33+
}
34+
35+
gatewayEvents: EventsClass = {
36+
functions: [],
37+
38+
parse: async () => {
39+
const discordEvents: GatewayEvent[] = [];
40+
const eventsPath = join(__dirname, 'events');
41+
const eventFiles = readdirSync(eventsPath).filter(file => file.endsWith('.js'));
42+
43+
for (const file of eventFiles) {
44+
const eventPath = join(eventsPath, file);
45+
const importedEvent = (await import(`file://${eventPath}`)).default;
2646

27-
this.on('ready', () => {
28-
console.log(`Logged in as ${this.user?.tag}`);
29-
});
47+
const theEvent = new importedEvent();
3048

31-
this.on('messageCreate', (message: Message) => {
32-
if (message.content === 'hi') {
33-
message.reply('hi');
49+
const eventName = file.replace(/\.[^/.]+$/, "");
50+
const eventCode = theEvent.code;
51+
const eventOnce: boolean = theEvent.once;
52+
53+
discordEvents.push({
54+
name: eventName,
55+
code: eventCode.bind(null, this.kogBot),
56+
once: eventOnce
57+
});
58+
}
59+
60+
return discordEvents;
61+
},
62+
63+
listen: async () => {
64+
const events: GatewayEvent[] = await this.gatewayEvents.parse();
65+
this.gatewayEvents.functions = events;
66+
67+
for (const event of this.gatewayEvents.functions) {
68+
if (event.once) {
69+
this.once(event.name, event.code);
70+
} else {
71+
this.on(event.name, event.code);
3472
}
35-
});
73+
}
3674
}
3775
}
3876
}

0 commit comments

Comments
 (0)