mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
change: ids to use bigint instead of string (#892)
* p1 of bigints change * shtuff fixes and bits * Commit from GitHub Actions (Lint) * finish bigint structs * typings fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * blame wolf * Commit from GitHub Actions (Lint) * foxed * Commit from GitHub Actions (Lint) * fix unit tests * Commit from GitHub Actions (Lint) * change: guildUpdate guild ID can't change * delete server has been renamed to delete guild * fixes Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com> Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
@@ -3,13 +3,16 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { VoiceState } from "../../types/voice/voice_state.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as VoiceState;
|
||||
|
||||
if (!payload.guildId) return;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const member = payload.member
|
||||
@@ -17,34 +20,40 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
payload.member,
|
||||
guild.id,
|
||||
)
|
||||
: await cacheHandlers.get("members", payload.userId);
|
||||
: await cacheHandlers.get("members", snowflakeToBigint(payload.userId));
|
||||
if (!member) return;
|
||||
|
||||
// No cached state before so lets make one for em
|
||||
const cachedState = guild.voiceStates.get(payload.userId);
|
||||
const cachedState = guild.voiceStates.get(snowflakeToBigint(payload.userId));
|
||||
|
||||
guild.voiceStates.set(
|
||||
payload.userId,
|
||||
payload,
|
||||
snowflakeToBigint(payload.userId),
|
||||
await structures.createDiscordenoVoiceState(guild.id, payload),
|
||||
);
|
||||
|
||||
await cacheHandlers.set("guilds", payload.guildId, guild);
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
|
||||
if (cachedState?.channelId !== payload.channelId) {
|
||||
if (
|
||||
cachedState?.channelId !==
|
||||
(payload.channelId ? snowflakeToBigint(payload.channelId) : null)
|
||||
) {
|
||||
// Either joined or moved channels
|
||||
if (payload.channelId) {
|
||||
if (cachedState?.channelId) { // Was in a channel before
|
||||
eventHandlers.voiceChannelSwitch?.(
|
||||
member,
|
||||
payload.channelId,
|
||||
snowflakeToBigint(payload.channelId),
|
||||
cachedState.channelId,
|
||||
);
|
||||
} else { // Was not in a channel before so user just joined
|
||||
eventHandlers.voiceChannelJoin?.(member, payload.channelId);
|
||||
eventHandlers.voiceChannelJoin?.(
|
||||
member,
|
||||
snowflakeToBigint(payload.channelId),
|
||||
);
|
||||
}
|
||||
} // Left the channel
|
||||
else if (cachedState?.channelId) {
|
||||
guild.voiceStates.delete(payload.userId);
|
||||
guild.voiceStates.delete(snowflakeToBigint(payload.userId));
|
||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user