Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
started adding an events system because that voiceStateUpdate file is…
Browse files Browse the repository at this point in the history
… horrible
  • Loading branch information
sebasptsch committed Apr 23, 2022
1 parent 89359df commit 06d8d64
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/classes/dynamicaEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// create a custom event emitter with typesafe emitters
import { CommandInteraction, GuildMember } from 'discord.js';
import { EventEmitter } from 'events';
import DynamicaPrimary from './primary';
import DynamicaSecondary from './secondary';
const emitter = new EventEmitter();

type Awaitable<T> = T | PromiseLike<T>;

interface DynamicaEventTypes {
secondaryJoined: [secondary: DynamicaSecondary, guildMember: GuildMember]
primaryJoined: [primary: DynamicaPrimary, guildMember: GuildMember]
secondaryLeft: [secondary: DynamicaSecondary, guildMember: GuildMember]
primaryLeft: [primary: DynamicaPrimary, guildMember: GuildMember]
}

export class DynamicaEventManager extends EventEmitter {
constructor() {
super();
}
emit<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.emit(event, listener);
}
on<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.on(event, listener);
}
once<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.once(event, listener);
}
prependListener<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.prependListener(event, listener);
}
prependOnceListener<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.prependOnceListener(event, listener);
}
removeListener<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.removeListener(event, listener);
}
removeAllListeners(event?: keyof DynamicaEventTypes) {
return super.removeAllListeners(event);
}
off<K extends keyof DynamicaEventTypes>(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable<void>) {
return super.off(event, listener);
}
listeners(event: keyof DynamicaEventTypes) {
return super.listeners(event);
}
rawListeners(event: keyof DynamicaEventTypes) {
return super.rawListeners(event);
}
listenerCount(event: keyof DynamicaEventTypes): number {
return super.listenerCount(event);
}
eventNames(): Array<keyof DynamicaEventTypes> {
return super.eventNames().map((event) => event as keyof DynamicaEventTypes);
}
}


emitter.emit('event', 'hello', 'world');
5 changes: 5 additions & 0 deletions src/utils/dynamicaEventManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DynamicaEventManager } from "@/classes/dynamicaEvent";

const dynamicaManager = new DynamicaEventManager()

export default dynamicaManager

0 comments on commit 06d8d64

Please sign in to comment.