Enhance module fixes with comments and error handling
Added a comment explaining the purpose of the module fixes and improved error handling for timestamp localization.
This commit is contained in:
parent
68660a2e06
commit
9fd141a158
1 changed files with 26 additions and 17 deletions
|
|
@ -1,20 +1,29 @@
|
|||
import { instead } from "spitroast"; // Assuming you have this from entry.ts setup
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
// 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 */;
|
||||
import { logger } from "@lib/utils/logger";
|
||||
import { FluxDispatcher } from "@metro/common";
|
||||
|
||||
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.");
|
||||
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);
|
||||
}
|
||||
|
||||
export default () => {
|
||||
FluxDispatcher.subscribe("I18N_LOAD_SUCCESS", onDispatch);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue