From 06d8d642dd289e0870c13004dbb6f0bd4d19013b Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Sun, 17 Apr 2022 12:04:02 +0000 Subject: [PATCH] started adding an events system because that voiceStateUpdate file is horrible --- src/classes/dynamicaEvent.ts | 60 +++++++++++++++++++++++++++++++ src/utils/dynamicaEventManager.ts | 5 +++ 2 files changed, 65 insertions(+) create mode 100644 src/classes/dynamicaEvent.ts create mode 100644 src/utils/dynamicaEventManager.ts 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