mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
refactor(gateway)!: Remove guildMemberChunk shard event (#3151)
* Remove guildMemberChunk shard event * use DiscordMemberWithUser for requestMembers
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
import type { DiscordGatewayPayload, DiscordGuildMembersChunk } from '@discordeno/types'
|
||||
import { PresenceStatus } from '@discordeno/types'
|
||||
import { camelize } from '@discordeno/utils'
|
||||
import type { Bot } from '../../index.js'
|
||||
|
||||
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload): Promise<any> {
|
||||
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMembersChunk
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
// If it's not enabled skip checks.
|
||||
if (!bot.gateway.cache.requestMembers?.enabled) return
|
||||
|
||||
return {
|
||||
guildId,
|
||||
members: payload.members.map((m) => bot.transformers.member(bot, m, guildId, bot.transformers.snowflake(m.user.id))),
|
||||
chunkIndex: payload.chunk_index,
|
||||
chunkCount: payload.chunk_count,
|
||||
notFound: payload.not_found?.map((id) => bot.transformers.snowflake(id)),
|
||||
presences: payload.presences?.map((presence) => ({
|
||||
user: bot.transformers.user(bot, presence.user),
|
||||
guildId,
|
||||
status: PresenceStatus[presence.status],
|
||||
activities: presence.activities.map((activity) => bot.transformers.activity(bot, activity)),
|
||||
clientStatus: {
|
||||
desktop: presence.client_status.desktop,
|
||||
mobile: presence.client_status.mobile,
|
||||
web: presence.client_status.web,
|
||||
},
|
||||
})),
|
||||
nonce: payload.nonce,
|
||||
}
|
||||
// If this request has no nonce, skip checks.
|
||||
if (!payload.nonce) return
|
||||
|
||||
const pending = bot.gateway.cache.requestMembers.pending.get(payload.nonce)
|
||||
|
||||
if (!pending) return
|
||||
|
||||
if (payload.chunk_count === 1) pending.members = payload.members
|
||||
else pending.members.push(...payload.members)
|
||||
|
||||
// If this is not the final chunk, just save to cache.
|
||||
if (payload.chunk_index + 1 < payload.chunk_count) return
|
||||
|
||||
// Resolve the promise that all requests are done.
|
||||
pending.resolve(camelize(pending.members))
|
||||
|
||||
// Delete the cache to clean up once its done.
|
||||
bot.gateway.cache.requestMembers.pending.delete(payload.nonce)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user