From efb71211ef7af784d3e2c2d28d16d41384db6b91 Mon Sep 17 00:00:00 2001 From: Tharki-God Date: Wed, 10 Apr 2024 04:15:27 +0530 Subject: [PATCH] cache fix --- src/renderer/coremods/commands/index.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/renderer/coremods/commands/index.ts b/src/renderer/coremods/commands/index.ts index cbbb24477..ec2fb74bc 100644 --- a/src/renderer/coremods/commands/index.ts +++ b/src/renderer/coremods/commands/index.ts @@ -264,6 +264,31 @@ async function injectApplicationCommandIndexStore(): Promise { }, ); } +async function injectCommandCache(): Promise { + const mod = await waitForProps<{ + getCachedCommand: (channel: Channel, id: string) => Promise; + }>("getCachedCommand"); + injector.after( + mod, + "getCachedCommand", + ([, id], res: { application?: RepluggedCommandSection; command?: AnyRepluggedCommand }) => { + const commandAndSectionsArray = Array.from(commandAndSections.values()).filter( + (commandAndSection) => commandAndSection.commands.size, + ); + const rpCached = commandAndSectionsArray + .map((commandAndSection) => ({ + application: commandAndSection.section, + command: Array.from(commandAndSection.commands.values()).find( + (command) => command.id === id, + ), + })) + .find((applicationAndCommand) => applicationAndCommand.command); + res.application ??= rpCached?.application; + res.command ??= rpCached?.command; + return res; + }, + ); +} async function injectProfileFetch(): Promise { const mod = await waitForProps<{ fetchProfile: (id: string) => Promise; @@ -279,6 +304,7 @@ export async function start(): Promise { await injectRepluggedBotIcon(); await injectRepluggedSectionIcon(); await injectApplicationCommandIndexStore(); + await injectCommandCache(); await injectProfileFetch(); loadCommands(); }