more thread fixes

This commit is contained in:
Skillz4Killz
2021-06-13 20:45:47 +00:00
committed by GitHub
parent 37d3952559
commit 950482c503
11 changed files with 51 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ import type { DiscordenoMember } from "./structures/member.ts";
import type { DiscordenoMessage } from "./structures/message.ts";
import type { PresenceUpdate } from "./types/activity/presence_update.ts";
import type { Emoji } from "./types/emojis/emoji.ts";
import { Thread } from "./util/channel_to_thread.ts";
import { Thread } from "./util/transformers/channel_to_thread.ts";
import { Collection } from "./util/collection.ts";
export const cache = {

View File

@@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { Channel } from "../../types/channels/channel.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { channelToThread } from "../../util/channel_to_thread.ts";
import { channelToThread } from "../../util/transformers/channel_to_thread.ts";
export async function handleThreadCreate(data: DiscordGatewayPayload) {
const payload = data.d as Channel;

View File

@@ -3,8 +3,9 @@ import { cacheHandlers } from "../../cache.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 { channelToThread } from "../../util/transformers/channel_to_thread.ts";
import { Collection } from "../../util/collection.ts";
import { threadMemberModified } from "../../util/transformers/thread_member_modified.ts";
export async function handleThreadListSync(data: DiscordGatewayPayload) {
const payload = data.d as ThreadListSync;
@@ -20,7 +21,7 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) {
eventHandlers.threadListSync?.(
new Collection(threads.map((t) => [t.id, t])),
payload.members,
payload.members.map((member) => threadMemberModified(member)),
snowflakeToBigint(payload.guildId)
);
}

View File

@@ -6,11 +6,11 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
const payload = data.d as ThreadMembersUpdate;
const thread = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
if (!thread) return;
thread.memberCount = payload.memberCount;
await cacheHandlers.set("channels", thread.id, thread);
await cacheHandlers.set("threads", thread.id, thread);
eventHandlers.threadMembersUpdate?.(payload);
}

View File

@@ -6,12 +6,16 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
const payload = data.d as ThreadMember;
const thread = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
if (!thread) return;
thread.member = payload;
const member = {
...payload,
id: snowflakeToBigint(payload.id),
userId: snowflakeToBigint(payload.userId),
joinTimestamp: Date.parse(payload.joinTimestamp),
};
await cacheHandlers.set("channels", thread.id, thread);
eventHandlers.threadMemberUpdate?.(payload);
eventHandlers.threadMemberUpdate?.(member, thread);
}

View File

@@ -1,10 +1,22 @@
export interface ThreadMember {
export interface ThreadMemberBase {
/** Any user-thread settings, currently only used for notifications */
flags: number;
}
export interface ThreadMember extends ThreadMemberBase {
/** The id of the thread */
id: string;
/** The id of the user */
userId: string;
/** The time the current user last joined the thread */
joinTimestamp: string;
/** Any user-thread settings, currently only used for notifications */
flags: number;
}
export interface ThreadMemberModified extends ThreadMemberBase {
/** The id of the thread */
id: bigint;
/** The id of the user */
userId: bigint;
/** The time the current user last joined the thread */
joinTimestamp: number;
}

View File

@@ -3,11 +3,11 @@ 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 { Thread } from "../../util/transformers/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";
import type { ThreadMember } from "../channels/threads/thread_member.ts";
import type { ThreadMemberModified } from "../channels/threads/thread_member.ts";
import type { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts";
import type { Emoji } from "../emojis/emoji.ts";
import type { GatewayPayload } from "../gateway/gateway_payload.ts";
@@ -133,9 +133,9 @@ export type EventHandlersDefinitions = {
/** Sent when a thread is updated */
threadUpdate: [thread: Thread, oldThread: Thread];
/** Sent when the bot gains access to threads */
threadListSync: [threads: Collection<bigint, Thread>, members: ThreadMember[], guildId: bigint];
threadListSync: [threads: Collection<bigint, Thread>, members: ThreadMemberModified[], guildId: bigint];
/** Sent when the current users thread member is updated */
threadMemberUpdate: [threadMember: ThreadMember];
threadMemberUpdate: [threadMember: ThreadMemberModified, thread: Thread];
/** Sent when anyone is added to or removed from a thread */
threadMembersUpdate: [update: ThreadMembersUpdate];
/** Sent when a thread is deleted */

View File

@@ -1,3 +1,4 @@
export * from "./transformers/mod.ts";
export * from "./bigint.ts";
export * from "./cache_members.ts";
export * from "./collection.ts";

View File

@@ -1,5 +1,5 @@
import { Channel } from "../types/channels/channel.ts";
import { snowflakeToBigint } from "./bigint.ts";
import { Channel } from "../../types/channels/channel.ts";
import { snowflakeToBigint } from "../bigint.ts";
export function channelToThread(channel: Channel) {
return {

View File

@@ -0,0 +1,2 @@
export * from "./channel_to_thread.ts";
export * from "./thread_member_modified.ts";

View File

@@ -0,0 +1,11 @@
import { ThreadMember, ThreadMemberModified } from "../../types/channels/threads/thread_member.ts";
import { snowflakeToBigint } from "../bigint.ts";
export function threadMemberModified(member: ThreadMember) {
return {
...member,
id: snowflakeToBigint(member.id),
userId: snowflakeToBigint(member.userId),
joinTimestamp: Date.parse(member.joinTimestamp),
} as ThreadMemberModified;
}