From 4f591320be466cfe00bf0f6b50ed78e55136cf21 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 2 May 2021 21:26:08 +0200 Subject: [PATCH] add: THREAD_LIST_SYNC handlere --- src/handlers/channels/THREAD_LIST_SYNC.ts | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/handlers/channels/THREAD_LIST_SYNC.ts diff --git a/src/handlers/channels/THREAD_LIST_SYNC.ts b/src/handlers/channels/THREAD_LIST_SYNC.ts new file mode 100644 index 000000000..659769d99 --- /dev/null +++ b/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -0,0 +1,34 @@ +import { eventHandlers } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; +import { DiscordenoChannel } from "../../structures/channel.ts"; +import { structures } from "../../structures/mod.ts"; +import { ThreadListSync } from "../../types/channels/threads/thread_list_sync.ts"; +import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { Collection } from "../../util/collection.ts"; + +export async function handleThreadListSync(data: DiscordGatewayPayload) { + const payload = data.d as ThreadListSync; + + const discordenoChannels = await Promise.all( + payload.threads.map(async (thread) => { + const discordenoChannel = await structures.createDiscordenoChannel( + thread, + payload.guildId, + ); + + await cacheHandlers.set( + "channels", + discordenoChannel.id, + discordenoChannel, + ); + + return discordenoChannel; + }), + ); + + const threads = new Collection( + discordenoChannels.map((t) => [t.id, t]), + ); + + eventHandlers.threadListSync?.(threads, payload.members, payload.guildId); +}