mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
refactor: rename controllers to handlers and handlers to helpers (#660)
* refactor: rename controllers to handlers and handlers to helpers * fmt
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordPayload, VoiceStateUpdatePayload } from "../../types/mod.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(data: DiscordPayload) {
|
||||
const payload = data.d as VoiceStateUpdatePayload;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
const member = payload.member
|
||||
? await structures.createMemberStruct(payload.member, guild.id)
|
||||
: await cacheHandlers.get("members", payload.user_id);
|
||||
if (!member) return;
|
||||
|
||||
// No cached state before so lets make one for em
|
||||
const cachedState = guild.voiceStates.get(payload.user_id);
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
|
||||
if (cachedState?.channelID !== payload.channel_id) {
|
||||
// Either joined or moved channels
|
||||
if (payload.channel_id) {
|
||||
if (cachedState?.channelID) { // Was in a channel before
|
||||
eventHandlers.voiceChannelSwitch?.(
|
||||
member,
|
||||
payload.channel_id,
|
||||
cachedState.channelID,
|
||||
);
|
||||
} else { // Was not in a channel before so user just joined
|
||||
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
||||
}
|
||||
} // Left the channel
|
||||
else if (cachedState?.channelID) {
|
||||
guild.voiceStates.delete(payload.user_id);
|
||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelID);
|
||||
}
|
||||
}
|
||||
|
||||
eventHandlers.voiceStateUpdate?.(member, payload);
|
||||
}
|
||||
Reference in New Issue
Block a user