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]),
|
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?.(
|
eventHandlers.guildEmojisUpdate?.(
|
||||||
guild,
|
guild,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export async function handleReady(
|
|||||||
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
|
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
|
||||||
|
|
||||||
// Start ready check in 2 seconds
|
// 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
|
// Wait 5 seconds to spawn next shard
|
||||||
await delay(5000);
|
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
|
// 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 */
|
/** 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);
|
const shard = ws.shards.get(shardId);
|
||||||
if (!shard) return;
|
if (!shard) return;
|
||||||
|
|
||||||
@@ -50,14 +50,14 @@ function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
|||||||
if (Date.now() - now > 10000) {
|
if (Date.now() - now > 10000) {
|
||||||
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
|
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
|
||||||
// Force execute the loaded function to prevent infinite loop
|
// Force execute the loaded function to prevent infinite loop
|
||||||
loaded(shardId);
|
await loaded(shardId);
|
||||||
} else {
|
} else {
|
||||||
// Not all guilds were loaded but 10 seconds haven't passed so check again
|
// 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 {
|
} else {
|
||||||
// All guilds were loaded
|
// All guilds were loaded
|
||||||
loaded(shardId);
|
await loaded(shardId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ async function loaded(shardId: number) {
|
|||||||
if (shardId === ws.lastShardId - 1) {
|
if (shardId === ws.lastShardId - 1) {
|
||||||
// Still some shards are loading so wait another 2 seconds for them
|
// Still some shards are loading so wait another 2 seconds for them
|
||||||
if (ws.shards.some((shard) => !shard.ready)) {
|
if (ws.shards.some((shard) => !shard.ready)) {
|
||||||
setTimeout(() => loaded(shardId), 2000);
|
setTimeout(async () => await loaded(shardId), 2000);
|
||||||
} else {
|
} else {
|
||||||
cache.isReady = true;
|
cache.isReady = true;
|
||||||
eventHandlers.ready?.();
|
eventHandlers.ready?.();
|
||||||
|
|||||||
@@ -46,14 +46,14 @@ export async function handleOnMessage(message: any, shardId: number) {
|
|||||||
ws.shards.get(shardId)!.resuming = true;
|
ws.shards.get(shardId)!.resuming = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resume(shardId);
|
await resume(shardId);
|
||||||
break;
|
break;
|
||||||
case DiscordGatewayOpcodes.InvalidSession:
|
case DiscordGatewayOpcodes.InvalidSession:
|
||||||
ws.log("INVALID_SESSION", { shardId, payload: messageData });
|
ws.log("INVALID_SESSION", { shardId, payload: messageData });
|
||||||
|
|
||||||
// When d is false we need to reidentify
|
// When d is false we need to reidentify
|
||||||
if (!messageData.d) {
|
if (!messageData.d) {
|
||||||
identify(shardId, ws.maxShards);
|
await identify(shardId, ws.maxShards);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export async function handleOnMessage(message: any, shardId: number) {
|
|||||||
ws.shards.get(shardId)!.resuming = true;
|
ws.shards.get(shardId)!.resuming = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resume(shardId);
|
await resume(shardId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (messageData.t === "RESUMED") {
|
if (messageData.t === "RESUMED") {
|
||||||
|
|||||||
@@ -51,5 +51,5 @@ export async function startGateway(options: StartGatewayOptions) {
|
|||||||
ws.botGatewayData.url = data.url;
|
ws.botGatewayData.url = data.url;
|
||||||
|
|
||||||
ws.spawnShards(ws.firstShardId);
|
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
|
// Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed
|
||||||
await delay(5000);
|
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,
|
...defaultTestOptions,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ Deno.test({
|
|||||||
// Assertions
|
// Assertions
|
||||||
assertExists(botId);
|
assertExists(botId);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// // Role
|
// // Role
|
||||||
|
|||||||
Reference in New Issue
Block a user