mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Merge branch 'fix-handlers-guilds' into fix-helpers
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.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) {
|
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuildBanAddRemove;
|
const payload = data.d as DiscordGuildBanAddRemove;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.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) {
|
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuildBanAddRemove;
|
const payload = data.d as DiscordGuildBanAddRemove;
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
||||||
|
|
||||||
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuild;
|
const payload = data.d as DiscordGuild;
|
||||||
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
|
const newGuild = await cacheHandlers.get("guilds", payload.id);
|
||||||
if (!cachedGuild) return;
|
if (!newGuild) return;
|
||||||
|
|
||||||
const keysToSkip = [
|
const keysToSkip = [
|
||||||
"roles",
|
"roles",
|
||||||
"guild_hashes",
|
"guildHashes",
|
||||||
"guild_id",
|
"guildId",
|
||||||
"max_members",
|
"maxMembers",
|
||||||
"emojis",
|
"emojis",
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
|||||||
if (keysToSkip.includes(key)) return;
|
if (keysToSkip.includes(key)) return;
|
||||||
|
|
||||||
// @ts-ignore index signature
|
// @ts-ignore index signature
|
||||||
const cachedValue = cachedGuild[key];
|
const cachedValue = newGuild[key];
|
||||||
if (cachedValue !== value) {
|
if (cachedValue !== value) {
|
||||||
// Guild create sends undefined and update sends false.
|
// Guild create sends undefined and update sends false.
|
||||||
if (!cachedValue && !value) return;
|
if (!cachedValue && !value) return;
|
||||||
@@ -34,12 +35,12 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore index signature
|
// @ts-ignore index signature
|
||||||
cachedGuild[key] = value;
|
newGuild[key] = value;
|
||||||
return { key, oldValue: cachedValue, value };
|
return { key, oldValue: cachedValue, value };
|
||||||
}
|
}
|
||||||
}).filter((change) => change) as GuildUpdateChange[];
|
}).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