fix(bot): properly handle thread list sync event (#3116)

* fix: Added threadListSync event support

* fix: Added threadListSync event support

* Update packages/bot/src/bot.ts

---------

Co-authored-by: ITOH <to@itoh.at>
This commit is contained in:
livelove1987
2023-08-28 21:47:30 +00:00
committed by GitHub
co-authored by ITOH
parent 1e8edb99c6
commit cd29c5f0b1
2 changed files with 9 additions and 10 deletions
+6 -8
View File
@@ -71,14 +71,11 @@ export function createBot(options: CreateBotOptions): Bot {
bot.gateway.connection = await bot.rest.getSessionInfo() bot.gateway.connection = await bot.rest.getSessionInfo()
// Check for overrides in the configuration // Check for overrides in the configuration
if (!options.gateway?.url) if (!options.gateway?.url) bot.gateway.url = bot.gateway.connection.url
bot.gateway.url = bot.gateway.connection.url;
if (!options.gateway?.totalShards) if (!options.gateway?.totalShards) bot.gateway.totalShards = bot.gateway.connection.shards
bot.gateway.totalShards = bot.gateway.connection.shards;
if (!options.gateway?.lastShardId) if (!options.gateway?.lastShardId) bot.gateway.lastShardId = bot.gateway.connection.shards - 1
bot.gateway.lastShardId = bot.gateway.connection.shards - 1;
} }
await bot.gateway.spawnShards() await bot.gateway.spawnShards()
@@ -90,7 +87,7 @@ export function createBot(options: CreateBotOptions): Bot {
} }
bot.helpers = createBotHelpers(bot) bot.helpers = createBotHelpers(bot)
if (options.applicationId) bot.applicationId = bot.transformers.snowflake(options.applicationId); if (options.applicationId) bot.applicationId = bot.transformers.snowflake(options.applicationId)
return bot return bot
} }
@@ -144,6 +141,7 @@ export interface EventHandlers {
automodActionExecution: (payload: AutoModerationActionExecution) => unknown automodActionExecution: (payload: AutoModerationActionExecution) => unknown
threadCreate: (thread: Channel) => unknown threadCreate: (thread: Channel) => unknown
threadDelete: (thread: Channel) => unknown threadDelete: (thread: Channel) => unknown
threadListSync: (payload: { guildId: bigint; channelIds?: bigint[]; threads: Channel[]; members: ThreadMember[] }) => unknown
threadMemberUpdate: (payload: { id: bigint; guildId: bigint; joinedAt: number; flags: number }) => unknown threadMemberUpdate: (payload: { id: bigint; guildId: bigint; joinedAt: number; flags: number }) => unknown
threadMembersUpdate: (payload: { id: bigint; guildId: bigint; addedMembers?: ThreadMember[]; removedMemberIds?: bigint[] }) => unknown threadMembersUpdate: (payload: { id: bigint; guildId: bigint; addedMembers?: ThreadMember[]; removedMemberIds?: bigint[] }) => unknown
threadUpdate: (thread: Channel) => unknown threadUpdate: (thread: Channel) => unknown
@@ -187,7 +185,7 @@ export interface EventHandlers {
guildId?: bigint guildId?: bigint
member?: Member member?: Member
user?: User user?: User
emoji: Emoji, emoji: Emoji
messageAuthorId?: bigint messageAuthorId?: bigint
}) => unknown }) => unknown
reactionRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji }) => unknown reactionRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji }) => unknown
@@ -6,7 +6,7 @@ export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload
const guildId = bot.transformers.snowflake(payload.guild_id) const guildId = bot.transformers.snowflake(payload.guild_id)
return { bot.events.threadListSync?.({
guildId, guildId,
channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)), channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)),
threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })), threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })),
@@ -14,6 +14,7 @@ export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload
id: member.id ? bot.transformers.snowflake(member.id) : undefined, id: member.id ? bot.transformers.snowflake(member.id) : undefined,
userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined, userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined,
joinTimestamp: Date.parse(member.join_timestamp), joinTimestamp: Date.parse(member.join_timestamp),
flags: member.flags,
})), })),
} })
} }