mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
refactor: decouple system events from command dispatch and add explicit system event handlers and improve gateway handling
This commit is contained in:
+20
-6
@@ -70,14 +70,24 @@ export class Unicord {
|
||||
return this.eventProcessor.register(`${type}:${event}`, handler);
|
||||
}
|
||||
|
||||
use(client: Unicord): this {
|
||||
this.commandManager.merge(client.commandManager);
|
||||
// TODO: inherit event listeners too
|
||||
return this;
|
||||
// This is kinda dumb maybe just remove
|
||||
// use(client: Unicord): this {
|
||||
// this.commandManager.merge(client.commandManager);
|
||||
// // TODO: inherit event listeners too
|
||||
// return this;
|
||||
// }
|
||||
|
||||
emitSystem(event: string, payload: UnicordEventContext) {
|
||||
return this.eventProcessor.emitSystem(event, payload);
|
||||
}
|
||||
|
||||
emit(type: UnicordEventType, event: string, context: UnicordCommandContext | UnicordEventContext, args: any[]) {
|
||||
this.eventProcessor.emit(`${type}:${event}`, context, args);
|
||||
emitCommand(
|
||||
type: UnicordEventType.ChatCommands | UnicordEventType.ApplicationCommands,
|
||||
event: string,
|
||||
context: UnicordCommandContext,
|
||||
args: any[],
|
||||
) {
|
||||
return this.eventProcessor.emitCommand(type, event, context, args);
|
||||
}
|
||||
|
||||
// TODO: can we automate defining these methods with some TS magic?
|
||||
@@ -104,6 +114,10 @@ export class Unicord {
|
||||
return this;
|
||||
}
|
||||
|
||||
onSystemEvent(event: string, handler: UnicordEventHandler): void {
|
||||
this.__onEvent(UnicordEventType.SystemEvent, event, handler);
|
||||
}
|
||||
|
||||
sendMessage = async (channel_id: string, message: Message | string) => {
|
||||
if (typeof message === 'string') {
|
||||
message = new Message().setContent(message);
|
||||
|
||||
Reference in New Issue
Block a user