swc/bundler/tests/.cache/deno/80b9641631a24e60aab47b5d0f8778bd4f159d8c.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

33 lines
1.2 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/handlers/guilds/GUILD_CREATE.ts
import { eventHandlers } from "../../bot.ts";
import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { Guild } from "../../types/guilds/guild.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { ws } from "../../ws/ws.ts";
export async function handleGuildCreate(data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as Guild;
// When shards resume they emit GUILD_CREATE again.
if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return;
const guild = await structures.createDiscordenoGuild(payload, shardId);
await cacheHandlers.set("guilds", guild.id, guild);
const shard = ws.shards.get(shardId);
if (shard?.unavailableGuildIds.has(guild.id)) {
await cacheHandlers.delete("unavailableGuilds", guild.id);
shard.unavailableGuildIds.delete(guild.id);
shard.lastAvailable = Date.now();
return eventHandlers.guildAvailable?.(guild);
}
if (!cache.isReady) return eventHandlers.guildLoaded?.(guild);
eventHandlers.guildCreate?.(guild);
}