summary refs log tree commit diff
path: root/gateway
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-04 12:18:49 +0200
committerGitHub <noreply@github.com>2021-09-04 12:18:49 +0200
commitbfdd9c10d82760f0cadc2d59aa2b467cdf14b02a (patch)
tree5477dcf75a9abf3d5d5124b319e9251728744fd1 /gateway
parent:bug: fix ReadyEventData (diff)
parent:pencil: added comments and updated type (diff)
downloadserver-bfdd9c10d82760f0cadc2d59aa2b467cdf14b02a.tar.xz
Merge pull request #320 from AlTech98/master
Added /guilds/:id/voice-states/ apis, VOICE_SERVER_UPDATE fix
Diffstat (limited to '')
-rw-r--r--gateway/src/opcodes/VoiceStateUpdate.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/gateway/src/opcodes/VoiceStateUpdate.ts

index fba0db1f..95a01608 100644 --- a/gateway/src/opcodes/VoiceStateUpdate.ts +++ b/gateway/src/opcodes/VoiceStateUpdate.ts
@@ -2,7 +2,7 @@ import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema"; import { Payload } from "../util/Constants"; import WebSocket from "../util/WebSocket"; import { check } from "./instanceOf"; -import { Config, emitEvent, Member, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util"; +import { Config, emitEvent, Guild, Member, Region, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util"; import { genVoiceToken } from "../util/SessionUtils"; // TODO: check if a voice server is setup // Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not. @@ -11,7 +11,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { check.call(this, VoiceStateUpdateSchema, data.d); const body = data.d as VoiceStateUpdateSchema; - let voiceState; + let voiceState: VoiceState; try { voiceState = await VoiceState.findOneOrFail({ where: { user_id: this.user_id } @@ -69,14 +69,21 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { //If it's null it means that we are leaving the channel and this event is not needed if (voiceState.channel_id !== null) { + const guild = await Guild.findOne({ id: voiceState.guild_id }) const regions = Config.get().regions; + let guildRegion: Region; + if (guild && guild.region) { + guildRegion = regions.available.filter(r => (r.id === guild.region))[0] + } else { + guildRegion = regions.available.filter(r => (r.id === regions.default))[0] + } await emitEvent({ event: "VOICE_SERVER_UPDATE", data: { token: voiceState.token, guild_id: voiceState.guild_id, - endpoint: regions.available[0].endpoint, //TODO return best endpoint or default + endpoint: guildRegion.endpoint, }, guild_id: voiceState.guild_id, } as VoiceServerUpdateEvent);