feat: New features in Portal
I've added registering to only an array of servers, disabling modules unregisters their commands, better component disabling and it all should work, however, I'll make the pull request a draft just in case.
Summary by CodeRabbit
-
New Features
- Runtime enable/disable controls for modules and individual components (commands, events, middleware, contexts)
- Server-specific enablement to restrict modules/components to particular servers
- Portal controls to toggle modules/components and query server-scoped enablement
-
User-visible Behavior
- Help command now filters and autocompletes commands by availability and server scope
-
Configuration
- Added
portal.keepRegisteredoption to control whether disabling unregisters associated handlers
- Added
I like the functionality that this PR brings but I can't really say it's something we'd accept at the moment
We did our best to retain a functional programming style for Robo.js, hence the lack of builders and conventional OOP patterns. This keeps our overhead minimal and goes well with file-based frameworks like Robo. A controller pattern violates this.
Another thing is, even though we have DJS coupled, we're actively trying to decouple DJS into its own thing away from the core. Adding this plus snowflakes in core APIs like Portal will make it harder to migrate later on.
An ideal solution would be more like:
- An independently exported function/object to interface with (DiscordManager?)
- Composable API rather than controllable
I'll keep your PR open because it has some good ideas, until we release this functionality using the above syntax. Until then, we'd appreciate it if you could split some parts of this PR into its own thing that we can accept now, such as the type enhancements
@Pkmmte 👋
create-discord-activity
npm i https://pkg.pr.new/Wave-Play/robo.js/create-discord-activity@434
create-robo
npm i https://pkg.pr.new/Wave-Play/robo.js/create-robo@434
@robojs/ai
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/ai@434
@robojs/ai-voice
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/ai-voice@434
@robojs/server
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/server@434
@robojs/better-stack
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/better-stack@434
@roboplay/plugin-confessions
npm i https://pkg.pr.new/Wave-Play/robo.js/@roboplay/plugin-confessions@434
@robojs/dev
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/dev@434
@roboplay/plugin-gpt
npm i https://pkg.pr.new/Wave-Play/robo.js/@roboplay/plugin-gpt@434
@robojs/maintenance
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/maintenance@434
@robojs/moderation
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/moderation@434
@roboplay/plugin-poll
npm i https://pkg.pr.new/Wave-Play/robo.js/@roboplay/plugin-poll@434
@robojs/sync
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/sync@434
robo.js
npm i https://pkg.pr.new/Wave-Play/robo.js@434
@roboplay/sage
npm i https://pkg.pr.new/Wave-Play/robo.js/@roboplay/sage@434
@robojs/analytics
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/analytics@434
@robojs/auth
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/auth@434
@robojs/cron
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/cron@434
@robojs/i18n
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/i18n@434
@robojs/patch
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/patch@434
@robojs/trpc
npm i https://pkg.pr.new/Wave-Play/robo.js/@robojs/trpc@434
commit: 24a2f49
Walkthrough
Adds a portal-based enablement system with per-module/command/event/middleware/context flags and server-specific restrictions, enforces these checks across handlers, introduces portal controllers/utilities, extends types and config for keepRegistered, and updates help filtering and gitignore.
Changes
| Cohort / File(s) | Summary |
|---|---|
Project Configuration \.gitignore |
Added .idea to ignore WebStorm project files. |
Global initialization packages/robo/src/core/globals.ts |
Introduces PortalEnabledState and PortalValues; getPortalValues() now returns typed portal state including enabledState and serverRestrictions; Globals.init and registerPortal ensure portal enablement and restrictions are initialized. |
Portal core & controllers packages/robo/src/core/portal.ts |
Reworked Portal to maintain per-type enabled maps and serverRestrictions; added public getters (enabledState, serverRestrictions, keepRegistered), setKeepRegistered, disableModule / enableModule, module/command/event/middleware/context controller factories, manifest scanning handling for serverOnly and disabled, and keepRegistered-driven unregister behavior. |
Portal utilities packages/robo/src/core/portal-utils.ts |
New portalUtils with helpers: isEnabled, setEnabled, isEnabledForServer, setServerOnly, unregisterModule* helpers, and applyModuleServerRestrictions; introduces ID and ComponentType types. |
Handler enforcement packages/robo/src/core/handlers.ts |
Adds enablement and server-restriction checks for modules, commands, contexts, events, and middleware across autocomplete, command, context-menu, and event handlers; skips disabled middleware; refines timeout/abort messaging and response shaping. |
Help command filtering packages/robo/src/default/commands/help.ts |
Filters commands by portal availability and server scope for lookups, categories, lists, and autocomplete results. |
Type declarations packages/robo/src/types/config.ts, packages/robo/src/types/global.d.ts, packages/robo/src/types/index.ts |
Config gains optional portal.keepRegistered; added global typings for PortalEnabledState, Portal, Flashcore, and RoboGlobal; expanded public type exports (context, middleware, handler, plugin, messaging types) and added export default {}. |
Sequence Diagram(s)
sequenceDiagram
actor User
participant Handler as Handler Entry
participant Portal as Portal (enabledState)
participant Utils as portalUtils
participant Middleware as Middleware Chain
participant Logic as Business Logic
User->>Handler: invoke (command/autocomplete/context/event)
Handler->>Portal: check module enabled?
alt module disabled
Handler-->>User: return early
else module enabled
Handler->>Portal: check item enabled? (command/event/context)
alt item disabled
Handler-->>User: return early
else item enabled
Handler->>Portal: check server restriction for item
alt not enabled for server
Handler-->>User: return early
else allowed for server
Handler->>Middleware: iterate middleware
loop for each middleware
Middleware->>Utils: isEnabled + isEnabledForServer?
alt middleware disabled or blocked
Middleware-->>Handler: skip
else allowed
Middleware->>Logic: execute
end
end
Handler->>Logic: execute core handler
Logic-->>User: respond
end
end
end
sequenceDiagram
participant Manifest as Manifest Loader
participant Portal as Portal
participant Utils as portalUtils
Manifest->>Portal: load entry with serverOnly/disabled?
alt entry.serverOnly present
Manifest->>Utils: setServerOnly for module/entries
end
alt entry.disabled present
Manifest->>Portal: update enabledState for module/entries
end
Portal->>Portal: store keepRegistered from Config if present
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
- Pay extra attention to portal state initialization in
globals.tsandregisterPortal. - Verify manifest scanning changes correctly propagate
serverOnlyanddisabledinto portal maps. - Review
disableModule/enableModuleinteractions withkeepRegistered(unregister vs disable). - Validate consistency of enablement/server checks across all handler paths and middleware gating.
- Inspect new controller factory implementations for correct shared-reference behavior.
Poem
🐰 I hopped through code with tiny paws, Flipped flags and stitched up portal laws. Modules sleep or spring to play, Servers choose who stays today. A rabbit cheers: enablement blooms! 🥕✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
| Title Check | ❓ Inconclusive | The title "feat: New features in Portal" uses the vague and generic term "New features," which fails to convey meaningful information about the specific changes in the changeset. While the title is correctly related to the Portal system enhancements, it does not clearly summarize the main changes such as per-module enablement, server-specific restrictions, disabling modules to unregister commands, or the new portal-utils API. A teammate scanning the repository history would not understand the primary change from this generic phrasing alone, making it insufficient as a clear summary according to the stated principles. | Consider revising the title to be more specific about the primary feature being introduced, such as "feat: Add per-module enablement and server-specific restrictions to Portal" or "feat: Add module disabling and server-only registration to Portal system." This would provide clarity about the main changes and make the commit history more informative for future reference. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Comment @coderabbitai help to get the list of available commands and usage tips.
@coderabbitai generate docstrings
✅ Actions performed
Initiated docstring generation; will generate only if new commits exist.
[!NOTE] Docstrings generation - SUCCESS Generated docstrings for this pull request at https://github.com/Wave-Play/robo.js/pull/457
Hi