mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
f
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
|
||||
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
|
||||
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
||||
|
||||
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
|
||||
if (!cachedGuild) return;
|
||||
const newGuild = await cacheHandlers.get("guilds", payload.id);
|
||||
if (!newGuild) return;
|
||||
|
||||
const keysToSkip = [
|
||||
"roles",
|
||||
"guild_hashes",
|
||||
"guild_id",
|
||||
"max_members",
|
||||
"guildHashes",
|
||||
"guildId",
|
||||
"maxMembers",
|
||||
"emojis",
|
||||
];
|
||||
|
||||
@@ -21,7 +22,7 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||
if (keysToSkip.includes(key)) return;
|
||||
|
||||
// @ts-ignore index signature
|
||||
const cachedValue = cachedGuild[key];
|
||||
const cachedValue = newGuild[key];
|
||||
if (cachedValue !== value) {
|
||||
// Guild create sends undefined and update sends false.
|
||||
if (!cachedValue && !value) return;
|
||||
@@ -34,12 +35,12 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||
}
|
||||
|
||||
// @ts-ignore index signature
|
||||
cachedGuild[key] = value;
|
||||
newGuild[key] = value;
|
||||
return { key, oldValue: cachedValue, value };
|
||||
}
|
||||
}).filter((change) => change) as GuildUpdateChange[];
|
||||
|
||||
await cacheHandlers.set("guilds", payload.id, cachedGuild);
|
||||
await cacheHandlers.set("guilds", payload.id, newGuild);
|
||||
|
||||
eventHandlers.guildUpdate?.(cachedGuild, changes);
|
||||
eventHandlers.guildUpdate?.(newGuild, changes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user