This repository has been archived by the owner on Apr 23, 2023. 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.
started adding an events system because that voiceStateUpdate file is…
… horrible
- Loading branch information
1 parent
89359df
commit 06d8d64
Showing
2 changed files
with
65 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
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'); |
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,5 @@ | ||
import { DynamicaEventManager } from "@/classes/dynamicaEvent"; | ||
|
||
const dynamicaManager = new DynamicaEventManager() | ||
|
||
export default dynamicaManager |