sync threads

This commit is contained in:
Skillz4Killz
2021-06-13 13:41:31 +00:00
committed by GitHub
parent f2177e8ca6
commit 0223518b43
2 changed files with 14 additions and 11 deletions

View File

@@ -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<bigint, DiscordenoChannel>(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)
);
}

View File

@@ -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<bigint, DiscordenoChannel>, members: ThreadMember[], guildId: bigint];
threadListSync: [channels: Collection<bigint, Thread>, 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 */