diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index 7d1a80e9..a2922e0c 100644
--- a/src/gateway/opcodes/VoiceStateUpdate.ts
+++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -17,19 +17,10 @@
*/
import { Payload, WebSocket } from "@spacebar/gateway";
-import {
- Config,
- emitEvent,
- Guild,
- Member,
- Region,
- VoiceServerUpdateEvent,
- VoiceState,
- VoiceStateUpdateEvent,
-} from "@spacebar/util";
+import { Config, emitEvent, Guild, Member, Region, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util";
import { genVoiceToken } from "../util/SessionUtils";
import { check } from "./instanceOf";
-import { VoiceStateUpdateSchema } from "@spacebar/schemas"
+import { VoiceStateUpdateSchema } from "@spacebar/schemas";
// TODO: check if a voice server is setup
// Notice: Bot users respect the voice channel's user limit, if set.
@@ -50,10 +41,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
voiceState = await VoiceState.findOneOrFail({
where: { user_id: this.user_id },
});
- if (
- voiceState.session_id !== this.session_id &&
- body.channel_id === null
- ) {
+ if (voiceState.session_id !== this.session_id && body.channel_id === null) {
//Should we also check guild_id === null?
//changing deaf or mute on a client that's not the one with the same session of the voicestate in the database should be ignored
return;
@@ -62,11 +50,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
if (voiceState.channel_id !== body.channel_id) isChanged = true;
//If a user change voice channel between guild we should send a left event first
- if (
- voiceState.guild_id &&
- voiceState.guild_id !== body.guild_id &&
- voiceState.session_id === this.session_id
- ) {
+ if (voiceState.guild_id && voiceState.guild_id !== body.guild_id && voiceState.session_id === this.session_id) {
await emitEvent({
event: "VOICE_STATE_UPDATE",
data: { ...voiceState.toPublicVoiceState(), channel_id: null },
@@ -89,12 +73,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
}
// if user left voice channel, send an update to previous channel/guild to let other people know that the user left
- if (
- voiceState.session_id === this.session_id &&
- body.guild_id == null &&
- body.channel_id == null &&
- (prevState?.guild_id || prevState?.channel_id)
- ) {
+ if (voiceState.session_id === this.session_id && body.guild_id == null && body.channel_id == null && (prevState?.guild_id || prevState?.channel_id)) {
await emitEvent({
event: "VOICE_STATE_UPDATE",
data: {
@@ -118,8 +97,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
}
//If the session changed we generate a new token
- if (voiceState.session_id !== this.session_id)
- voiceState.token = genVoiceToken();
+ if (voiceState.session_id !== this.session_id) voiceState.token = genVoiceToken();
voiceState.session_id = this.session_id;
const { member } = voiceState;
@@ -146,13 +124,9 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
const regions = Config.get().regions;
let guildRegion: Region;
if (guild && guild.region) {
- guildRegion = regions.available.filter(
- (r) => r.id === guild.region,
- )[0];
+ guildRegion = regions.available.filter((r) => r.id === guild.region)[0];
} else {
- guildRegion = regions.available.filter(
- (r) => r.id === regions.default,
- )[0];
+ guildRegion = regions.available.filter((r) => r.id === regions.default)[0];
}
await emitEvent({
@@ -161,15 +135,11 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
token: voiceState.token,
guild_id: voiceState.guild_id,
endpoint: guildRegion.endpoint,
- channel_id: voiceState.guild_id
- ? undefined
- : voiceState.channel_id, // only DM voice calls have this set, and DM channel is one where guild_id is null
+ channel_id: voiceState.guild_id ? undefined : voiceState.channel_id, // only DM voice calls have this set, and DM channel is one where guild_id is null
},
user_id: voiceState.user_id,
} as VoiceServerUpdateEvent);
}
- console.log(
- `[Gateway] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`,
- );
+ console.log(`[Gateway] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`);
}
|