From 0223518b4399b6314c8fd49aac2e4e1ad2f74bf0 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 13 Jun 2021 13:41:31 +0000 Subject: [PATCH] sync threads --- src/handlers/channels/THREAD_LIST_SYNC.ts | 18 ++++++++++-------- src/types/discordeno/event_handlers.ts | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/handlers/channels/THREAD_LIST_SYNC.ts b/src/handlers/channels/THREAD_LIST_SYNC.ts index 7745267e1..599fe6350 100644 --- a/src/handlers/channels/THREAD_LIST_SYNC.ts +++ b/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -5,22 +5,24 @@ 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 { snowflakeToBigint } from "../../util/bigint.ts"; +import { channelToThread } from "../../util/channel_to_thread.ts"; import { Collection } from "../../util/collection.ts"; export async function handleThreadListSync(data: DiscordGatewayPayload) { const payload = data.d as ThreadListSync; - const discordenoChannels = await Promise.all( + const threads = await Promise.all( payload.threads.map(async (thread) => { - const discordenoChannel = await structures.createDiscordenoChannel(thread, snowflakeToBigint(payload.guildId)); + const threadData = channelToThread(thread); + await cacheHandlers.set("threads", threadData.id, threadData); - await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); - - return discordenoChannel; + return threadData; }) ); - const threads = new Collection(discordenoChannels.map((t) => [t.id, t])); - - eventHandlers.threadListSync?.(threads, payload.members, snowflakeToBigint(payload.guildId)); + eventHandlers.threadListSync?.( + new Collection(threads.map((t) => [t.id, t])), + payload.members, + snowflakeToBigint(payload.guildId) + ); } diff --git a/src/types/discordeno/event_handlers.ts b/src/types/discordeno/event_handlers.ts index 66bf035f4..93e86c73d 100644 --- a/src/types/discordeno/event_handlers.ts +++ b/src/types/discordeno/event_handlers.ts @@ -3,6 +3,7 @@ import type { DiscordenoGuild } from "../../structures/guild.ts"; import type { DiscordenoMember } from "../../structures/member.ts"; import type { DiscordenoMessage } from "../../structures/message.ts"; import type { DiscordenoRole } from "../../structures/role.ts"; +import { Thread } from "../../util/channel_to_thread.ts"; import type { Collection } from "../../util/collection.ts"; import type { PresenceUpdate } from "../activity/presence_update.ts"; import type { StageInstance } from "../channels/stage_instance.ts"; @@ -128,11 +129,11 @@ export type EventHandlersDefinitions = { /** Sent when a Stage instance has been updated. */ stageInstanceUpdate: [instance: StageInstance]; /** Sent when a thread is created */ - threadCreate: [channel: DiscordenoChannel]; + threadCreate: [channel: Thread]; /** Sent when a thread is updated */ - threadUpdate: [cahnnel: DiscordenoChannel, oldChannel: DiscordenoChannel]; + threadUpdate: [channel: Thread, oldChannel: Thread]; /** Sent when the bot gains access to threads */ - threadListSync: [channels: Collection, members: ThreadMember[], guildId: bigint]; + threadListSync: [channels: Collection, members: ThreadMember[], guildId: bigint]; /** Sent when the current users thread member is updated */ threadMemberUpdate: [threadMember: ThreadMember]; /** Sent when anyone is added to or removed from a thread */