mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
sync threads
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user