From 4366f0087fd512fbf3579ad20624846745359119 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 20:56:22 +0100 Subject: [PATCH 1/4] Fix: cache --- src/cache.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index e10b234b1..86df37a7f 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -82,6 +82,9 @@ export function createCache( presences: options.tableCreator(bot, "presences"), // threads: options.tableCreator(bot, "threads"), unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), + dispatchedGuildIds: new Set(), + dispatchedChannelIds: new Set(), + activeGuildIds: new Set(), executedSlashCommands: new Set(), fetchAllMembersProcessingRequests: new Map(), } as AsyncCache; @@ -103,6 +106,9 @@ export function createCache( presences: options.tableCreator(bot, "presences"), // threads: options.tableCreator(bot, "threads"), unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), + dispatchedGuildIds: new Set(), + dispatchedChannelIds: new Set(), + activeGuildIds: new Set(), executedSlashCommands: new Set(), fetchAllMembersProcessingRequests: new Map(), } as Cache; From 780cbde53dcf293ec2db7a40aaeaa330e7f42445 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 22:58:52 +0100 Subject: [PATCH 2/4] Fix: dispatchRequirements --- src/util/dispatch_requirements.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/dispatch_requirements.ts b/src/util/dispatch_requirements.ts index 72b99bea6..700f047ee 100644 --- a/src/util/dispatch_requirements.ts +++ b/src/util/dispatch_requirements.ts @@ -6,8 +6,6 @@ import { SnakeCasedPropertiesDeep } from "../types/util.ts"; const processing = new Set(); export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - if (!bot.isReady) return; - // DELETE MEANS WE DONT NEED TO FETCH. CREATE SHOULD HAVE DATA TO CACHE if (data.t && ["GUILD_CREATE", "GUILD_DELETE"].includes(data.t)) return; From 76678ecdeab67ac94d5948aeefaf30f91b671f6e Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 23:01:01 +0100 Subject: [PATCH 3/4] Update dispatch_requirements.ts --- src/util/dispatch_requirements.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/dispatch_requirements.ts b/src/util/dispatch_requirements.ts index 700f047ee..0f99169b8 100644 --- a/src/util/dispatch_requirements.ts +++ b/src/util/dispatch_requirements.ts @@ -17,11 +17,11 @@ export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload (data.d as any)?.guild_id) ?? "" ); - if (!id || bot.activeGuildIds.has(id)) return; + if (!id || bot.cache.activeGuildIds.has(id)) return; // If this guild is in cache, it has not been swept and we can cancel if (await bot.cache.guilds.has(id)) { - bot.activeGuildIds.add(id); + bot.cache.activeGuildIds.add(id); return; } From 4502b0f0c1755520e42a579356a089df9604518a Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 23:28:44 +0100 Subject: [PATCH 4/4] Fix: dispatchRequirements --- src/util/dispatch_requirements.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/util/dispatch_requirements.ts b/src/util/dispatch_requirements.ts index 0f99169b8..e8bbc08e0 100644 --- a/src/util/dispatch_requirements.ts +++ b/src/util/dispatch_requirements.ts @@ -46,19 +46,19 @@ export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload // New guild id has appeared, fetch all relevant data bot.events.debug(`[DISPATCH] New Guild ID has appeared: ${id} in ${data.t} event`); - const rawGuild = (await bot.helpers + const guild = (await bot.helpers .getGuild(id, { counts: true, addToCache: false, }) .catch(console.log)) as SnakeCasedPropertiesDeep | undefined; - if (!rawGuild) { + if (!guild) { processing.delete(id); return bot.events.debug(`[DISPATCH] Guild ID ${id} failed to fetch.`); } - bot.events.debug(`[DISPATCH] Guild ID ${id} has been found. ${rawGuild.name}`); + bot.events.debug(`[DISPATCH] Guild ID ${id} has been found. ${guild.name}`); const [channels, botMember] = await Promise.all([ bot.helpers.getChannels(id, false), @@ -71,18 +71,10 @@ export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload if (!botMember || !channels) { processing.delete(id); return bot.events.debug( - `[DISPATCH] Guild ID ${id} Name: ${rawGuild.name} failed. Unable to get botMember or channels` + `[DISPATCH] Guild ID ${id} Name: ${guild.name} failed. Unable to get botMember or channels` ); } - const guild = bot.transformers.guild(bot, { - guild: { - ...rawGuild, - member_count: rawGuild.approximate_member_count, - }, - shardId, - }); - // Add to cache await bot.cache.guilds.set(id, guild); bot.cache.dispatchedGuildIds.delete(id);