From 26019cbfd1971482ce7ccf16fb0ebb15f0b2986b Mon Sep 17 00:00:00 2001 From: ayntee Date: Wed, 10 Mar 2021 20:27:32 +0400 Subject: [PATCH] feat(controllers): add VOICE_SERVER_UPDATE event (#652) --- src/api/controllers/VOICE_SERVER_UPDATE.ts | 15 +++++++++++++++ src/api/controllers/mod.ts | 2 ++ src/types/options.ts | 6 ++++++ 3 files changed, 23 insertions(+) create mode 100644 src/api/controllers/VOICE_SERVER_UPDATE.ts diff --git a/src/api/controllers/VOICE_SERVER_UPDATE.ts b/src/api/controllers/VOICE_SERVER_UPDATE.ts new file mode 100644 index 000000000..9548321dd --- /dev/null +++ b/src/api/controllers/VOICE_SERVER_UPDATE.ts @@ -0,0 +1,15 @@ +import { eventHandlers } from "../../bot.ts"; +import { + DiscordPayload, + DiscordVoiceServerUpdateEvent, +} from "../../types/mod.ts"; +import { cacheHandlers } from "./cache.ts"; + +export async function handleVoiceServerUpdate(data: DiscordPayload) { + const payload = data.d as DiscordVoiceServerUpdateEvent; + + const guild = await cacheHandlers.get("guilds", payload.guild_id); + if (!guild) return; + + eventHandlers.voiceServerUpdate?.(payload.token, guild, payload.endpoint); +} diff --git a/src/api/controllers/mod.ts b/src/api/controllers/mod.ts index ce97927b5..8ef8cd3fa 100644 --- a/src/api/controllers/mod.ts +++ b/src/api/controllers/mod.ts @@ -55,6 +55,7 @@ import { handleInternalGuildRoleDelete, handleInternalGuildRoleUpdate, } from "./roles.ts"; +import { handleVoiceServerUpdate } from "./VOICE_SERVER_UPDATE.ts"; export let controllers = { READY: handleInternalReady, @@ -90,6 +91,7 @@ export let controllers = { TYPING_START: handleInternalTypingStart, USER_UPDATE: handleInternalUserUpdate, VOICE_STATE_UPDATE: handleInternalVoiceStateUpdate, + VOICE_SERVER_UPDATE: handleVoiceServerUpdate, WEBHOOKS_UPDATE: handleInternalWebhooksUpdate, INTEGRATION_CREATE: handleInternalIntegrationCreate, INTEGRATION_UPDATE: handleInternalIntegrationUpdate, diff --git a/src/types/options.ts b/src/types/options.ts index 72db39794..3340e0611 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -225,6 +225,12 @@ export interface EventHandlers { member: Member, voiceState: VoiceStateUpdatePayload, ) => unknown; + /** Sent when a guild's voice server is updated. This is sent when initially connecting to voice, and when the current voice instance fails over to a new server. */ + voiceServerUpdate?: ( + token: string, + guild: Guild, + endpoint: string, + ) => unknown; /** Sent when a guild channel's webhook is created, updated, or deleted. */ webhooksUpdate?: (channelID: string, guildID: string) => unknown; /** Sent when a member has passed the guild's Membership Screening requirements */