mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 16:00:07 +00:00
feat: thread handlers
This commit is contained in:
18
src/bot.ts
18
src/bot.ts
@@ -85,7 +85,7 @@ import { StatusUpdate } from "./types/gateway/statusUpdate.ts";
|
||||
import { calculateBits, calculatePermissions } from "./util/permissions.ts";
|
||||
import { transformScheduledEvent } from "./transformers/scheduledEvent.ts";
|
||||
import { DiscordenoScheduledEvent } from "./transformers/scheduledEvent.ts";
|
||||
import { transformThreadMember } from "./transformers/threadMember.ts";
|
||||
import { DiscordenoThreadMember, transformThreadMember } from "./transformers/threadMember.ts";
|
||||
import { transformApplicationCommandOption } from "./transformers/applicationCommandOption.ts";
|
||||
import { transformApplicationCommand } from "./transformers/applicationCommand.ts";
|
||||
import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts";
|
||||
@@ -142,6 +142,10 @@ export function createEventHandlers(events: Partial<EventHandlers>): EventHandle
|
||||
|
||||
return {
|
||||
debug: events.debug ?? ignore,
|
||||
threadCreate: events.threadCreate ?? ignore,
|
||||
threadDelete: events.threadDelete ?? ignore,
|
||||
threadMembersUpdate: events.threadMembersUpdate ?? ignore,
|
||||
threadUpdate: events.threadUpdate ?? ignore,
|
||||
scheduledEventCreate: events.scheduledEventCreate ?? ignore,
|
||||
scheduledEventUpdate: events.scheduledEventUpdate ?? ignore,
|
||||
scheduledEventDelete: events.scheduledEventDelete ?? ignore,
|
||||
@@ -630,6 +634,18 @@ export interface GatewayManager {
|
||||
|
||||
export interface EventHandlers {
|
||||
debug: (text: string, ...args: any[]) => unknown;
|
||||
threadCreate: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
threadDelete: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
threadMembersUpdate: (
|
||||
bot: Bot,
|
||||
payload: {
|
||||
id: bigint;
|
||||
guildId: bigint;
|
||||
addedMembers?: DiscordenoThreadMember[];
|
||||
removedMemberIds?: bigint[];
|
||||
}
|
||||
) => unknown;
|
||||
threadUpdate: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
scheduledEventCreate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
scheduledEventUpdate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
scheduledEventDelete: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
|
||||
@@ -6,5 +6,5 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
|
||||
// bot.events.threadCreate(bot, payload);
|
||||
bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
||||
// const payload = data.d as Channel;
|
||||
// const cachedChannel = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
|
||||
// if (!cachedChannel) return;
|
||||
// await cacheHandlers.delete("threads", snowflakeToBigint(payload.id));
|
||||
// await cacheHandlers.forEach("DELETE_MESSAGES_FROM_CHANNEL", { channelId: snowflakeToBigint(payload.id) });
|
||||
// eventHandlers.threadDelete?.(cachedChannel);
|
||||
export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { ThreadListSync } from "../../types/channels/threads/threadListSync.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleThreadListSync(data: DiscordGatewayPayload) {
|
||||
// const payload = data.d as ThreadListSync;
|
||||
// const threads = await Promise.all(
|
||||
// payload.threads.map(async (thread) => {
|
||||
// const threadData = channelToThread(thread);
|
||||
// await cacheHandlers.set("threads", threadData.id, threadData);
|
||||
// return threadData;
|
||||
// })
|
||||
// );
|
||||
// eventHandlers.threadListSync?.(
|
||||
// new Collection(threads.map((t) => [t.id, t])),
|
||||
// payload.members.map((member) => threadMemberModified(member)),
|
||||
// snowflakeToBigint(payload.guildId)
|
||||
// );
|
||||
export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ThreadListSync>;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
return {
|
||||
guildId,
|
||||
channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)),
|
||||
threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })),
|
||||
members: payload.members.map((member) => ({
|
||||
id: member.id ? bot.transformers.snowflake(member.id) : undefined,
|
||||
userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined,
|
||||
joinTimestamp: Date.parse(member.join_timestamp),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { ThreadMembersUpdate } from "../../types/channels/threads/threadMembersUpdate.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
|
||||
// const payload = data.d as ThreadMembersUpdate;
|
||||
// const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
|
||||
// if (!thread) return;
|
||||
// thread.memberCount = payload.memberCount;
|
||||
// await cacheHandlers.set("threads", thread.id, thread);
|
||||
// eventHandlers.threadMembersUpdate?.(threadMembersUpdateModified(payload));
|
||||
export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ThreadMembersUpdate>;
|
||||
bot.events.threadMembersUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
addedMembers: payload.added_members?.map((member) => bot.transformers.threadMember(bot, member)),
|
||||
removedMemberIds: payload.removed_member_ids?.map((id) => bot.transformers.snowflake(id)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import { ThreadMember } from "../../types/channels/threads/threadMember.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
||||
// const payload = data.d as ThreadMember;
|
||||
// // The id field is omitted from the thread member dispatched within the GUILD_CREATE gateway event.
|
||||
// const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id!));
|
||||
// if (!thread) return;
|
||||
// thread.botIsMember = true;
|
||||
// await cacheHandlers.set("threads", thread.id, thread);
|
||||
// const member = {
|
||||
// ...payload,
|
||||
// id: snowflakeToBigint(payload.id!),
|
||||
// userId: snowflakeToBigint(payload.userId!),
|
||||
// joinTimestamp: Date.parse(payload.joinTimestamp),
|
||||
// };
|
||||
// eventHandlers.threadMemberUpdate?.(member, thread);
|
||||
export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
// This event is documented for completeness, but unlikely to be used by most bots
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
export async function handleThreadUpdate(data: DiscordGatewayPayload) {
|
||||
// const payload = data.d as Channel;
|
||||
// const oldThread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
|
||||
// if (!oldThread) return;
|
||||
// const thread = channelToThread(payload);
|
||||
// await cacheHandlers.set("threads", thread.id, thread);
|
||||
// eventHandlers.threadUpdate?.(thread, oldThread);
|
||||
export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
|
||||
bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user