diff --git a/src/bot.ts b/src/bot.ts index a6e5b5648..4333d0135 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,6 +1,6 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts"; import { rest } from "./rest/rest.ts"; -import type { EventHandlerFunctions } from "./types/discordeno/eventHandlers.ts"; +import type { EventHandlers } from "./types/discordeno/eventHandlers.ts"; import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts"; import { snowflakeToBigint } from "./util/bigint.ts"; import { GATEWAY_VERSION } from "./util/constants.ts"; @@ -11,7 +11,7 @@ export let secretKey = ""; export let botId = 0n; export let applicationId = 0n; -export let eventHandlers: EventHandlerFunctions = {}; +export let eventHandlers: EventHandlers = {}; export let proxyWSURL = `wss://gateway.discord.gg`; @@ -44,12 +44,12 @@ export async function startBot(config: BotConfig) { ws.spawnShards(); } -export function replaceEventHandlers(newEventHandlers: EventHandlerFunctions) { +export function replaceEventHandlers(newEventHandlers: EventHandlers) { eventHandlers = newEventHandlers; } /** Allows you to dynamically update the event handlers by passing in new eventHandlers */ -export function updateEventHandlers(newEventHandlers: EventHandlerFunctions) { +export function updateEventHandlers(newEventHandlers: EventHandlers) { Object.assign(eventHandlers, newEventHandlers); } @@ -67,5 +67,5 @@ export interface BotConfig { token: string; compress?: boolean; intents: (DiscordGatewayIntents | keyof typeof DiscordGatewayIntents)[]; - eventHandlers?: EventHandlerFunctions; + eventHandlers?: EventHandlers; } diff --git a/src/plugins/proxyEvents.ts b/src/plugins/proxyEvents.ts index 80ee5ace8..5af8bb67e 100644 --- a/src/plugins/proxyEvents.ts +++ b/src/plugins/proxyEvents.ts @@ -1,10 +1,10 @@ import { eventHandlers, replaceEventHandlers } from "../bot.ts"; -import type { EventHandlerFunctions } from "../types/discordeno/eventHandlers.ts"; +import type { EventHandlers } from "../types/discordeno/eventHandlers.ts"; import type { EventEmitter } from "https://deno.land/std@0.96.0/node/events.ts"; export function proxyEvent(emitter: EventEmitter) { replaceEventHandlers(new Proxy(eventHandlers, { - get(target, prop: keyof EventHandlerFunctions) { + get(target, prop: keyof EventHandlers) { return target[prop] !== undefined ? target[prop] : ((...args: unknown[]) => emitter.emit(prop, ...args)); }, })); diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index 887d5f504..a460928db 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -28,7 +28,7 @@ import { VoiceServerUpdate } from "../voice/voice_server_update.ts"; import { DebugArg } from "./debug_arg.ts"; import { GuildUpdateChange } from "./guild_update_change.ts"; -export type EventHandlers = { +export type EventHandlersDefinitions = { /** Sent when a new Slash Command is created, relevant to the current user. */ applicationCommandCreate: [data: ApplicationCommandCreateUpdateDelete]; /** Sent when a Slash Command relevant to the current user is updated. */ @@ -160,6 +160,6 @@ export type EventHandlers = { inviteDelete: [data: InviteDelete]; } -export type EventHandlerFunctions = { - [E in keyof EventHandlers]?: (...args: EventHandlers[E]) => unknown; +export type EventHandlers = { + [E in keyof EventHandlersDefinitions]?: (...args: EventHandlersDefinitions[E]) => unknown; };