refactor!: remove global context, update command/event attachment#59
refactor!: remove global context, update command/event attachment#59
Conversation
BREAKING CHANGE: The global context module has been removed. Commands and events must now access the client and logger via instance properties after being attached. The `prefix` option is now a function. Update your usage accordingly.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant architectural refactorings aimed at enhancing the modularity, flexibility, and maintainability of the framework. The core change involves decoupling commands and events from a global context, requiring them to be explicitly attached to a client instance. This shift, along with a more dynamic prefix handling and an improved module loading system, provides greater control and clarity over component lifecycles and dependencies. The changes also include updates to the build process and internationalization features to support these architectural improvements. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a major and beneficial refactoring by removing the global client context, which makes the architecture cleaner and more robust. Commands and events are now explicitly attached to the client instance. The module loading system has been significantly improved to be more flexible and extensible, supporting various export patterns including factory functions. Additionally, the project's dual CJS/ESM package support has been enhanced. My review includes a few suggestions, mainly concerning a potential infinite recursion in the new module loader and a misconfiguration in package.json.
There was a problem hiding this comment.
Code Review
This pull request is a major and well-executed refactor that removes the global client context, replacing it with a more robust attachment system for commands and events. This significantly improves the framework's design, making it more modular and testable. The changes are consistent across the codebase, and the new APIs for creating commands and handling modules are a great improvement. I've found a few issues to address: a potential infinite recursion bug in the new module loader, some unreachable code, and a bug in one of the updated examples. Overall, this is excellent work.
src/utils/util.ts
Outdated
| if (ctx.isMessage()) { | ||
| return toAllowedLocale(ctx.data.guild?.preferredLocale) ?? Locale.EnglishUS; | ||
| } | ||
| return Locale.EnglishUS; | ||
| } |
There was a problem hiding this comment.
The type of ctx is Context<ChatInputCommandInteraction | Message>, which means ctx.isInteraction() or ctx.isMessage() will always be true within this function. The final if (ctx.isMessage()) block and the subsequent return statement are structured in a way that makes the final return unreachable. This can be simplified.
return toAllowedLocale(ctx.data.guild?.preferredLocale) ?? Locale.EnglishUS;
}Add MAX_EXPORT_FACTORY_DEPTH constant and enforce it in registerExport to prevent infinite recursion when registering export factories. Rename messages.ts to lang.ts and update imports. Remove unused prefix log and package.json imports field.
BREAKING CHANGE: The global context module has been removed. Commands and events must now access the client and logger via instance properties after being attached. The
prefixoption is now a function. Update your usage accordingly.