Skip to content

Commit

Permalink
cache fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Apr 9, 2024
1 parent b60e408 commit efb7121
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/renderer/coremods/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,31 @@ async function injectApplicationCommandIndexStore(): Promise<void> {
},
);
}
async function injectCommandCache(): Promise<void> {
const mod = await waitForProps<{
getCachedCommand: (channel: Channel, id: string) => Promise<void>;
}>("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<void> {
const mod = await waitForProps<{
fetchProfile: (id: string) => Promise<void>;
Expand All @@ -279,6 +304,7 @@ export async function start(): Promise<void> {
await injectRepluggedBotIcon();
await injectRepluggedSectionIcon();
await injectApplicationCommandIndexStore();
await injectCommandCache();
await injectProfileFetch();
loadCommands();
}
Expand Down

0 comments on commit efb7121

Please sign in to comment.