mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
fix: nonce bug not resolving requests
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
GuildMemberUpdatePayload,
|
GuildMemberUpdatePayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../../util/cache.ts";
|
||||||
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { structures } from "../structures/structures.ts";
|
import { structures } from "../structures/structures.ts";
|
||||||
import { cacheHandlers } from "./cache.ts";
|
import { cacheHandlers } from "./cache.ts";
|
||||||
|
|
||||||
@@ -94,11 +95,11 @@ export async function handleInternalGuildMembersChunk(data: DiscordPayload) {
|
|||||||
if (data.t !== "GUILD_MEMBERS_CHUNK") return;
|
if (data.t !== "GUILD_MEMBERS_CHUNK") return;
|
||||||
|
|
||||||
const payload = data.d as GuildMemberChunkPayload;
|
const payload = data.d as GuildMemberChunkPayload;
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
await Promise.all(
|
const members = await Promise.all(
|
||||||
payload.members.map((member) => structures.createMember(member, guild.id)),
|
payload.members.map((member) =>
|
||||||
|
structures.createMember(member, payload.guild_id)
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
||||||
@@ -110,8 +111,16 @@ export async function handleInternalGuildMembersChunk(data: DiscordPayload) {
|
|||||||
|
|
||||||
if (payload.chunk_index + 1 === payload.chunk_count) {
|
if (payload.chunk_index + 1 === payload.chunk_count) {
|
||||||
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
||||||
resolve(
|
// Only 1 chunk most likely is all members or users only request a small amount of users
|
||||||
await cacheHandlers.filter("members", (m) => m.guilds.has(guild.id)),
|
if (payload.chunk_count === 1) {
|
||||||
|
return resolve(new Collection(members.map((m) => [m.id, m])));
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolve(
|
||||||
|
await cacheHandlers.filter(
|
||||||
|
"members",
|
||||||
|
(m) => m.guilds.has(payload.guild_id),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
} from "../structures/structures.ts";
|
} from "../structures/structures.ts";
|
||||||
import { cacheHandlers } from "./cache.ts";
|
import { cacheHandlers } from "./cache.ts";
|
||||||
|
|
||||||
|
/** This function is the internal handler for the ready event. Users can override this with controllers if desired. */
|
||||||
export async function handleInternalReady(
|
export async function handleInternalReady(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
shardID: number,
|
shardID: number,
|
||||||
@@ -47,6 +48,7 @@ export async function handleInternalReady(
|
|||||||
allowNextShard();
|
allowNextShard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is the internal handler for the presence update event. Users can override this with controllers if desired. */
|
||||||
export async function handleInternalPresenceUpdate(data: DiscordPayload) {
|
export async function handleInternalPresenceUpdate(data: DiscordPayload) {
|
||||||
if (data.t !== "PRESENCE_UPDATE") return;
|
if (data.t !== "PRESENCE_UPDATE") return;
|
||||||
|
|
||||||
@@ -57,11 +59,13 @@ export async function handleInternalPresenceUpdate(data: DiscordPayload) {
|
|||||||
return eventHandlers.presenceUpdate?.(payload, oldPresence);
|
return eventHandlers.presenceUpdate?.(payload, oldPresence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is the internal handler for the typings event. Users can override this with controllers if desired. */
|
||||||
export function handleInternalTypingStart(data: DiscordPayload) {
|
export function handleInternalTypingStart(data: DiscordPayload) {
|
||||||
if (data.t !== "TYPING_START") return;
|
if (data.t !== "TYPING_START") return;
|
||||||
eventHandlers.typingStart?.(data.d as TypingStartPayload);
|
eventHandlers.typingStart?.(data.d as TypingStartPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is the internal handler for the user update event. Users can override this with controllers if desired. */
|
||||||
export async function handleInternalUserUpdate(data: DiscordPayload) {
|
export async function handleInternalUserUpdate(data: DiscordPayload) {
|
||||||
if (data.t !== "USER_UPDATE") return;
|
if (data.t !== "USER_UPDATE") return;
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ export async function handleInternalUserUpdate(data: DiscordPayload) {
|
|||||||
return eventHandlers.botUpdate?.(userData);
|
return eventHandlers.botUpdate?.(userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is the internal handler for the voice state update event. Users can override this with controllers if desired. */
|
||||||
export async function handleInternalVoiceStateUpdate(data: DiscordPayload) {
|
export async function handleInternalVoiceStateUpdate(data: DiscordPayload) {
|
||||||
if (data.t !== "VOICE_STATE_UPDATE") return;
|
if (data.t !== "VOICE_STATE_UPDATE") return;
|
||||||
|
|
||||||
@@ -127,6 +132,7 @@ export async function handleInternalVoiceStateUpdate(data: DiscordPayload) {
|
|||||||
eventHandlers.voiceStateUpdate?.(member, payload);
|
eventHandlers.voiceStateUpdate?.(member, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is the internal handler for the webhooks update event. Users can override this with controllers if desired. */
|
||||||
export function handleInternalWebhooksUpdate(data: DiscordPayload) {
|
export function handleInternalWebhooksUpdate(data: DiscordPayload) {
|
||||||
if (data.t !== "WEBHOOKS_UPDATE") return;
|
if (data.t !== "WEBHOOKS_UPDATE") return;
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -62,10 +62,15 @@ export async function startBot(config: BotConfig) {
|
|||||||
spawnShards(botGatewayData, identifyPayload, 0, botGatewayData.shards);
|
spawnShards(botGatewayData, identifyPayload, 0, botGatewayData.shards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Allows you to dynamically update the event handlers by passing in new eventHandlers */
|
||||||
export function updateEventHandlers(newEventHandlers: EventHandlers) {
|
export function updateEventHandlers(newEventHandlers: EventHandlers) {
|
||||||
eventHandlers = newEventHandlers;
|
eventHandlers = {
|
||||||
|
...eventHandlers,
|
||||||
|
...newEventHandlers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** INTERNAL LIB function used to set the bot ID once the READY event is sent by Discord. */
|
||||||
export function setBotID(id: string) {
|
export function setBotID(id: string) {
|
||||||
if (botID !== id) botID = id;
|
if (botID !== id) botID = id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,8 @@ export async function requestAllMembers(
|
|||||||
resolve: Function,
|
resolve: Function,
|
||||||
options?: FetchMembersOptions,
|
options?: FetchMembersOptions,
|
||||||
) {
|
) {
|
||||||
const nonce = `${guild.id}-${Math.random().toString()}`;
|
const nonce = `${guild.id}-${Date.now()}`;
|
||||||
cache.fetchAllMembersProcessingRequests.set(nonce, resolve);
|
cache.fetchAllMembersProcessingRequests.set(nonce, resolve);
|
||||||
|
|
||||||
return requestGuildMembers(guild.id, guild.shardID, nonce, options);
|
return requestGuildMembers(guild.id, guild.shardID, nonce, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user