mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
missing awaits
This commit is contained in:
@@ -14,7 +14,7 @@ export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||
payload.emojis.map((emoji) => [emoji.id ?? emoji.name, emoji]),
|
||||
);
|
||||
|
||||
cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
|
||||
eventHandlers.guildEmojisUpdate?.(
|
||||
guild,
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function handleReady(
|
||||
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
|
||||
|
||||
// Start ready check in 2 seconds
|
||||
setTimeout(() => checkReady(payload, shardId, now), 2000);
|
||||
setTimeout(async () => await checkReady(payload, shardId, now), 2000);
|
||||
|
||||
// Wait 5 seconds to spawn next shard
|
||||
await delay(5000);
|
||||
@@ -41,7 +41,7 @@ export async function handleReady(
|
||||
|
||||
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
|
||||
/** This function checks if the shard is fully loaded */
|
||||
function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
||||
async function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
||||
const shard = ws.shards.get(shardId);
|
||||
if (!shard) return;
|
||||
|
||||
@@ -50,14 +50,14 @@ function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
||||
if (Date.now() - now > 10000) {
|
||||
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
|
||||
// Force execute the loaded function to prevent infinite loop
|
||||
loaded(shardId);
|
||||
await loaded(shardId);
|
||||
} else {
|
||||
// Not all guilds were loaded but 10 seconds haven't passed so check again
|
||||
setTimeout(() => checkReady(payload, shardId, now), 2000);
|
||||
setTimeout(async () => await checkReady(payload, shardId, now), 2000);
|
||||
}
|
||||
} else {
|
||||
// All guilds were loaded
|
||||
loaded(shardId);
|
||||
await loaded(shardId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ async function loaded(shardId: number) {
|
||||
if (shardId === ws.lastShardId - 1) {
|
||||
// Still some shards are loading so wait another 2 seconds for them
|
||||
if (ws.shards.some((shard) => !shard.ready)) {
|
||||
setTimeout(() => loaded(shardId), 2000);
|
||||
setTimeout(async () => await loaded(shardId), 2000);
|
||||
} else {
|
||||
cache.isReady = true;
|
||||
eventHandlers.ready?.();
|
||||
|
||||
@@ -46,14 +46,14 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
ws.shards.get(shardId)!.resuming = true;
|
||||
}
|
||||
|
||||
resume(shardId);
|
||||
await resume(shardId);
|
||||
break;
|
||||
case DiscordGatewayOpcodes.InvalidSession:
|
||||
ws.log("INVALID_SESSION", { shardId, payload: messageData });
|
||||
|
||||
// When d is false we need to reidentify
|
||||
if (!messageData.d) {
|
||||
identify(shardId, ws.maxShards);
|
||||
await identify(shardId, ws.maxShards);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
ws.shards.get(shardId)!.resuming = true;
|
||||
}
|
||||
|
||||
resume(shardId);
|
||||
await resume(shardId);
|
||||
break;
|
||||
default:
|
||||
if (messageData.t === "RESUMED") {
|
||||
|
||||
@@ -51,5 +51,5 @@ export async function startGateway(options: StartGatewayOptions) {
|
||||
ws.botGatewayData.url = data.url;
|
||||
|
||||
ws.spawnShards(ws.firstShardId);
|
||||
ws.cleanupLoadingShards();
|
||||
await ws.cleanupLoadingShards();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ Deno.test({
|
||||
// Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed
|
||||
await delay(5000);
|
||||
|
||||
if (!cache.guilds.has(guild.id)) throw new Error("The guild seemed to be created but it was not cached.");
|
||||
if (!cache.guilds.has(guild.id)) {
|
||||
throw new Error("The guild seemed to be created but it was not cached.");
|
||||
}
|
||||
},
|
||||
...defaultTestOptions,
|
||||
});
|
||||
|
||||
@@ -42,7 +42,6 @@ Deno.test({
|
||||
// Assertions
|
||||
assertExists(botId);
|
||||
},
|
||||
...defaultTestOptions,
|
||||
});
|
||||
|
||||
// // Role
|
||||
|
||||
Reference in New Issue
Block a user