This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04e75a4
commit a5ad2e8
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Awaitable, ClientEvents } from "discord.js"; | ||
import type MeteoriumClient from "../classes/client.js"; | ||
|
||
export * as ReadyInit from "./readyInit.js"; | ||
export * as InteractionHandler from "./interactionHandler.js"; | ||
export * as PresenceResumption from "./presenceResumption.js"; | ||
|
||
export type MeteoriumEvent<EventName extends keyof ClientEvents> = { | ||
event: EventName; | ||
callback(client: MeteoriumClient, ...args: ClientEvents[EventName]): Awaitable<any>; | ||
once: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ClientEvents, Collection } from "discord.js"; | ||
import type MeteoriumClient from "../classes/client.js"; | ||
import type { LoggingNamespace } from "../classes/logging.js"; | ||
|
||
import * as events from "./eventsEntry.js"; | ||
|
||
export default class MeteoriumEventManager { | ||
public events: Collection<string, events.MeteoriumEvent<any>>; | ||
public client: MeteoriumClient; | ||
public logging: LoggingNamespace; | ||
|
||
public constructor(client: MeteoriumClient) { | ||
this.events = new Collection(); | ||
this.client = client; | ||
this.logging = client.logging.registerNamespace("EventManager"); | ||
} | ||
|
||
public register() { | ||
const regNS = this.logging.getNamespace("Registration"); | ||
|
||
regNS.info("Registering events"); | ||
for (const [Name, { Event }] of Object.entries(events)) { | ||
regNS.verbose(`Registering -> ${Name}${Event.once ? " (Once)" : ""}`); | ||
this.events.set(Name, Event); | ||
} | ||
|
||
return; | ||
} | ||
|
||
public hook() { | ||
const hookNS = this.logging.registerNamespace("Hooking"); | ||
|
||
hookNS.info("Hooking events to client"); | ||
for (const [Name, Event] of this.events) { | ||
hookNS.verbose(`Hooking -> ${Name}`); | ||
if (Event.once) this.client.once(Event.event, Event.callback); | ||
else this.client.on(Event.event, Event.callback); | ||
} | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { MeteoriumEvent } from "./eventsEntry.js"; | ||
|
||
export const Event: MeteoriumEvent<"interactionCreate"> = { | ||
event: "interactionCreate", | ||
async callback(client, interaction) {}, | ||
once: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { MeteoriumEvent } from "./eventsEntry.js"; | ||
|
||
export const Event: MeteoriumEvent<"shardResume"> = { | ||
event: "shardResume", | ||
async callback(client) {}, | ||
once: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { MeteoriumEvent } from "./eventsEntry.js"; | ||
|
||
export const Event: MeteoriumEvent<"ready"> = { | ||
event: "ready", | ||
async callback(client) {}, | ||
once: true, | ||
}; |