add: THREAD_LIST_SYNC handlere

This commit is contained in:
ITOH
2021-05-02 21:26:08 +02:00
parent 48606a67c6
commit 4f591320be
+34
View File
@@ -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<string, DiscordenoChannel>(
discordenoChannels.map((t) => [t.id, t]),
);
eventHandlers.threadListSync?.(threads, payload.members, payload.guildId);
}