mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
fix
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordVoiceServerUpdate, VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
|
||||
import {
|
||||
DiscordVoiceServerUpdate,
|
||||
VoiceServerUpdate,
|
||||
} from "../../types/voice/voice_server_update.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = snakeKeysToCamelCase(data.d as DiscordVoiceServerUpdate) as VoiceServerUpdate;
|
||||
const payload = snakeKeysToCamelCase<VoiceServerUpdate>(
|
||||
data.d as DiscordVoiceServerUpdate,
|
||||
);
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -2,51 +2,58 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordVoiceState } from "../../types/voice/voice_state.ts";
|
||||
import { DiscordGuildMemberWithUser } from "../../types/mod.ts";
|
||||
import {
|
||||
DiscordVoiceState,
|
||||
VoiceState,
|
||||
} from "../../types/voice/voice_state.ts";
|
||||
import {
|
||||
camelKeysToSnakeCase,
|
||||
snakeKeysToCamelCase,
|
||||
} from "../../util/utils.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordVoiceState;
|
||||
if (!payload.guild_id) return;
|
||||
const payload = snakeKeysToCamelCase<VoiceState>(
|
||||
data.d as DiscordVoiceState,
|
||||
);
|
||||
if (!payload.guildId) return;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const member = payload.member
|
||||
? await structures.createDiscordenoMember(payload.member, guild.id)
|
||||
: await cacheHandlers.get("members", payload.user_id);
|
||||
? await structures.createDiscordenoMember(
|
||||
camelKeysToSnakeCase<DiscordGuildMemberWithUser>(payload),
|
||||
guild.id,
|
||||
)
|
||||
: await cacheHandlers.get("members", payload.userId);
|
||||
if (!member) return;
|
||||
|
||||
// No cached state before so lets make one for em
|
||||
const cachedState = guild.voiceStates.get(payload.user_id);
|
||||
const cachedState = guild.voiceStates.get(payload.userId);
|
||||
|
||||
guild.voiceStates.set(payload.user_id, {
|
||||
...payload,
|
||||
guildId: payload.guild_id,
|
||||
channelId: payload.channel_id || "",
|
||||
userId: payload.user_id,
|
||||
sessionId: payload.session_id,
|
||||
selfDeaf: payload.self_deaf,
|
||||
selfMute: payload.self_mute,
|
||||
selfStream: payload.self_stream || false,
|
||||
});
|
||||
guild.voiceStates.set(
|
||||
payload.userId,
|
||||
payload,
|
||||
);
|
||||
|
||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
await cacheHandlers.set("guilds", payload.guildId, guild);
|
||||
|
||||
if (cachedState?.channelId !== payload.channel_id) {
|
||||
if (cachedState?.channelId !== payload.channelId) {
|
||||
// Either joined or moved channels
|
||||
if (payload.channel_id) {
|
||||
if (payload.channelId) {
|
||||
if (cachedState?.channelId) { // Was in a channel before
|
||||
eventHandlers.voiceChannelSwitch?.(
|
||||
member,
|
||||
payload.channel_id,
|
||||
payload.channelId,
|
||||
cachedState.channelId,
|
||||
);
|
||||
} else { // Was not in a channel before so user just joined
|
||||
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
||||
eventHandlers.voiceChannelJoin?.(member, payload.channelId);
|
||||
}
|
||||
} // Left the channel
|
||||
else if (cachedState?.channelId) {
|
||||
guild.voiceStates.delete(payload.user_id);
|
||||
guild.voiceStates.delete(payload.userId);
|
||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user