mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(gateway): set a nonce if none is provided for gateway.requestMembers (#4057)
* fix(gateway): set a nonce if none is provided for gateway.requestMembers * chore: update comment for gateway.requestMembers to clarify about gateway.cache.requestMembers.enabled * chore: make the comment better * fix: add node:crypto import to deno import map
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"imports": {
|
"imports": {
|
||||||
"node:buffer": "https://deno.land/std@0.176.0/node/buffer.ts",
|
"node:buffer": "https://deno.land/std@0.176.0/node/buffer.ts",
|
||||||
|
"node:crypto": "https://deno.land/std@0.176.0/node/crypto.ts",
|
||||||
"node:fs": "https://deno.land/std@0.176.0/node/fs.ts",
|
"node:fs": "https://deno.land/std@0.176.0/node/fs.ts",
|
||||||
"node:fs/promises": "https://deno.land/std@0.176.0/node/fs/promises.ts",
|
"node:fs/promises": "https://deno.land/std@0.176.0/node/fs/promises.ts",
|
||||||
"node:events": "https://deno.land/std@0.176.0/node/events.ts",
|
"node:events": "https://deno.land/std@0.176.0/node/events.ts",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { randomBytes } from 'node:crypto'
|
||||||
import {
|
import {
|
||||||
type AtLeastOne,
|
type AtLeastOne,
|
||||||
type BigString,
|
type BigString,
|
||||||
@@ -506,22 +507,32 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate
|
|||||||
options.limit = options.userIds.length
|
options.limit = options.userIds.length
|
||||||
}
|
}
|
||||||
|
|
||||||
const members =
|
if (!options?.nonce) {
|
||||||
!gateway.cache.requestMembers.enabled || !options?.nonce
|
let nonce = ''
|
||||||
? []
|
|
||||||
: new Promise<Camelize<DiscordMemberWithUser[]>>((resolve, reject) => {
|
|
||||||
// Should never happen.
|
|
||||||
if (!gateway.cache.requestMembers.enabled || !options?.nonce) {
|
|
||||||
reject(new Error("Can't request the members without the nonce or with the feature disabled."))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
gateway.cache.requestMembers.pending.set(options.nonce, {
|
while (!nonce || gateway.cache.requestMembers.pending.has(nonce)) {
|
||||||
nonce: options.nonce,
|
nonce = randomBytes(16).toString('hex')
|
||||||
resolve,
|
}
|
||||||
members: [],
|
|
||||||
})
|
options ??= { limit: 0 }
|
||||||
|
options.nonce = nonce
|
||||||
|
}
|
||||||
|
|
||||||
|
const members = !gateway.cache.requestMembers.enabled
|
||||||
|
? []
|
||||||
|
: new Promise<Camelize<DiscordMemberWithUser[]>>((resolve, reject) => {
|
||||||
|
// Should never happen.
|
||||||
|
if (!gateway.cache.requestMembers.enabled || !options?.nonce) {
|
||||||
|
reject(new Error("Can't request the members without the nonce or with the feature disabled."))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway.cache.requestMembers.pending.set(options.nonce, {
|
||||||
|
nonce: options.nonce,
|
||||||
|
resolve,
|
||||||
|
members: [],
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
await gateway.sendPayload(shardId, {
|
await gateway.sendPayload(shardId, {
|
||||||
op: GatewayOpcodes.RequestGuildMembers,
|
op: GatewayOpcodes.RequestGuildMembers,
|
||||||
@@ -807,7 +818,7 @@ export interface GatewayManager extends Required<CreateGatewayManagerOptions> {
|
|||||||
*/
|
*/
|
||||||
editShardStatus: (shardId: number, data: StatusUpdate) => Promise<void>
|
editShardStatus: (shardId: number, data: StatusUpdate) => Promise<void>
|
||||||
/**
|
/**
|
||||||
* Fetches the list of members for a guild over the gateway.
|
* Fetches the list of members for a guild over the gateway. If `gateway.cache.requestMembers.enabled` is not set, this function will return an empty array and you'll have to handle the `GUILD_MEMBERS_CHUNK` events yourself.
|
||||||
*
|
*
|
||||||
* @param guildId - The ID of the guild to get the list of members for.
|
* @param guildId - The ID of the guild to get the list of members for.
|
||||||
* @param options - The parameters for the fetching of the members.
|
* @param options - The parameters for the fetching of the members.
|
||||||
|
|||||||
Reference in New Issue
Block a user