diff --git a/src/classes/dynamicaEvent.ts b/src/classes/dynamicaEvent.ts new file mode 100644 index 0000000..a6c26a0 --- /dev/null +++ b/src/classes/dynamicaEvent.ts @@ -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 | PromiseLike; + +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(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.emit(event, listener); + } + on(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.on(event, listener); + } + once(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.once(event, listener); + } + prependListener(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.prependListener(event, listener); + } + prependOnceListener(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.prependOnceListener(event, listener); + } + removeListener(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + return super.removeListener(event, listener); + } + removeAllListeners(event?: keyof DynamicaEventTypes) { + return super.removeAllListeners(event); + } + off(event: K, listener: (...args: DynamicaEventTypes[K]) => Awaitable) { + 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 { + return super.eventNames().map((event) => event as keyof DynamicaEventTypes); + } +} + + +emitter.emit('event', 'hello', 'world'); \ No newline at end of file diff --git a/src/utils/dynamicaEventManager.ts b/src/utils/dynamicaEventManager.ts new file mode 100644 index 0000000..51e7cda --- /dev/null +++ b/src/utils/dynamicaEventManager.ts @@ -0,0 +1,5 @@ +import { DynamicaEventManager } from "@/classes/dynamicaEvent"; + +const dynamicaManager = new DynamicaEventManager() + +export default dynamicaManager \ No newline at end of file