From 68660a2e06058eef1423a2ccc4fba2bbf07c9c18 Mon Sep 17 00:00:00 2001 From: OTKUSteyler <90369564+OTKUSteyler@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:00:06 +0100 Subject: [PATCH] Improve timestamp handling and scoreCommand patching Refactor timestamp handling and patch scoreCommand for null checks. --- src/core/fixes.ts | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/core/fixes.ts b/src/core/fixes.ts index 1791066..2f01cf4 100644 --- a/src/core/fixes.ts +++ b/src/core/fixes.ts @@ -1,29 +1,20 @@ -/** - * Why do we need this exactly? It's simple, to fight the side effects caused by when you - * initialize modules not in the right time or when you're not supposed to. - * Back then, we had major bugs like the mixing of light and dark themes and AMOLED option getting ignored. - * Nowadays, there are only three which I can spot: Hindi timestamps, crashing on some native components and slower startup time. - * - @pylixonly - */ +import { instead } from "spitroast"; // Assuming you have this from entry.ts setup -import { logger } from "@lib/utils/logger"; -import { FluxDispatcher } from "@metro/common"; +// Find the module with scoreCommand (use your mod's finder utils, like findByCode if you have one) +const searchModule = /* Your finder here, e.g., findByCode("toLocaleLowerCase", "scoreCommand") or similar */; -function onDispatch({ locale }: { locale: string }) { - // Timestamps - require moment lazily so we avoid top-level import cost - try { - // require at runtime (lazy) to keep startup/bundle lighter - // eslint-disable-next-line @typescript-eslint/no-var-requires - const moment = require("moment"); - moment.locale(locale.toLowerCase()); - } catch (e) { - logger.error("Failed to fix timestamps (lazy moment)...", e); - } - - // We're done here! - FluxDispatcher.unsubscribe("I18N_LOAD_SUCCESS", onDispatch); +if (searchModule) { + instead(searchModule.scoreCommand, (args, orig) => { + // Add null check before the lowercase call + const [command, query] = args; // Assuming args structure based on typical Discord code + if (query === undefined || query === null) { + return 0; // Or some safe default score to skip + } + // Or target the exact line: wrap the string op + // e.g., if the buggy line is something like str.toLocaleLowerCase(), replace with str?.toLocaleLowerCase() ?? "" + return orig(...args); + }); + logger.log("Patched scoreCommand to handle undefined values!"); +} else { + logger.warn("Couldn't find scoreCommand module to patch."); } - -export default () => { - FluxDispatcher.subscribe("I18N_LOAD_SUCCESS", onDispatch); -};