Skip to content

Testingbranch#9

Merged
Coder-soft merged 4 commits into
masterfrom
Testingbranch
Dec 8, 2025
Merged

Testingbranch#9
Coder-soft merged 4 commits into
masterfrom
Testingbranch

Conversation

@Coder-soft
Copy link
Copy Markdown
Owner

@Coder-soft Coder-soft commented Dec 8, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved shutdown reliability by cleaning up rate limiter resources.
    • Partial scheduled-event deletions are now handled gracefully, broadcasting a minimal payload when full data isn't available.
  • Refactoring

    • Strengthened type safety across event handlers and plugin wiring.
    • Plugin event helper types consolidated into a single abstract helper shape for clearer plugin APIs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 8, 2025

Walkthrough

Adds type refinements and small API-surface typings: introduces internal MessageParams handling, exports EventHelpers type, updates plugin event typings, improves Discord event typing and partial scheduled-event delete handling, calls shutdownRateLimiter during shutdown, and performs a tiny plugin router cast refactor.

Changes

Cohort / File(s) Summary
Message params / route typing
src/api/routes/messages.ts
Adds internal MessageParams type and getParams(req) cast; ensures channelId defaults to empty string while preserving messageId and emoji.
Discord event typing & partial delete handling
src/discord/events/index.ts
Replaces any casts with discord.js types (User, GuildScheduledEvent); when a guildScheduledEventDelete is partial, broadcasts a minimal partial payload instead of full serialization.
Shutdown: rate limiter cleanup
src/index.ts
Imports shutdownRateLimiter and invokes it in shutdown() before unloading plugins and exiting.
Plugin router minor refactor
src/plugins/manager.ts
Casts pluginSubRouter to Router and uses a local router variable to call use() (stylistic/refactor only).
Plugin SDK type export
src/plugins/sdk.ts
Exports new EventHelpers type alias = ReturnType<typeof createEventHelpers>.
Plugin types updated to use exported helpers type
src/types/plugin.types.ts
Replaces inline helpers object type in HoloPlugin.events with the exported EventHelpers type; imports EventHelpers from ../plugins/sdk.js.
Event types: partial delete payload
src/types/events.types.ts
GuildScheduledEventDeleteEvent.data updated to `SerializedScheduledEvent

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to: GuildScheduledEventDelete partial-path handling and corresponding type change in src/types/events.types.ts.
  • Verify usages of the new EventHelpers type across plugins and that no call sites assume the previous concrete helper shape.
  • Confirm shutdown ordering: shutdownRateLimiter() executes at the intended point and has no lifecycle race with plugin unload.

Possibly related PRs

  • Testingbranch #1 — also modifies Discord scheduled-event delete flow to support broadcasting partial delete payloads; directly related to the guildScheduledEventDelete changes.

Poem

🐰 I hopped through types and cleaned the trail,

EventHelpers tucked in my pale tail,
A partial delete left crumbs to share,
Rate limiter napped with careful care,
Puff of code — and a tidy hare! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Testingbranch' is vague and does not describe the actual changes in the pull request, which include type improvements, event handling enhancements, shutdown cleanup, and plugin type refactoring. Replace the title with a descriptive summary of the main changes, such as 'Improve type safety and add shutdown cleanup for Discord event handling' or 'Enhance type safety and event handling across messages, Discord events, and plugins'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Testingbranch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 8, 2025

Greptile Overview

Greptile Summary

Improved type safety across the plugin system by replacing any type assertions with proper TypeScript types.

  • Replaced any casts with proper Discord.js types (User, GuildScheduledEvent) in event handlers
  • Created MessageParams interface to replace any type assertion in route parameter handling
  • Extracted EventHelpers type to eliminate duplication between sdk.ts and plugin.types.ts
  • Added rate limiter cleanup call in shutdown sequence to prevent memory leaks
  • Improved code clarity with explanatory comments for type assertions
  • Replaced non-null assertion operator with explicit type assertion in plugin router setup

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it only improves type safety without changing runtime behavior
  • Score of 5 reflects that all changes are type-safety improvements with no functional changes. The type assertions are validated to be correct (serializer functions expect the exact types used), the new EventHelpers export eliminates duplication, and the rate limiter cleanup prevents memory leaks. No breaking changes or logical issues found.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/api/routes/messages.ts 5/5 Replaced any type with proper MessageParams interface for type safety
src/discord/events/index.ts 5/5 Replaced any type assertions with proper Discord.js types (User, GuildScheduledEvent) and added explanatory comments
src/index.ts 5/5 Added rate limiter cleanup call in shutdown handler to prevent memory leaks
src/plugins/manager.ts 5/5 Replaced non-null assertion operator with explicit type assertion and added clarifying comment
src/plugins/sdk.ts 5/5 Exported EventHelpers type for reuse, improving type inference and reducing duplication
src/types/plugin.types.ts 5/5 Replaced inline event helpers type with imported EventHelpers type, removing duplication

Sequence Diagram

sequenceDiagram
    participant Main as index.ts
    participant PM as PluginManager
    participant Plugin as HoloPlugin
    participant Router as Express Router
    participant EventBus as PluginEventBus
    participant Discord as Discord Client

    Main->>PM: setContext(client, io, config, app)
    Main->>PM: loadPlugins()
    PM->>Plugin: import plugin file
    PM->>PM: validate metadata
    
    alt Plugin has events hook
        PM->>EventBus: createEventHelpers(eventBus)
        PM->>Plugin: events(helpers, ctx)
        Plugin-->>PM: return EventSubscription[]
        PM->>PM: store subscriptions
    end
    
    alt Plugin has routes hook
        PM->>Router: create plugin sub-router
        PM->>Plugin: routes(wrappedRouter, ctx)
        Plugin->>Router: register GET/POST/etc endpoints
        PM->>Router: mount at /api/plugins/{name}
    end
    
    PM->>Plugin: onLoad(ctx)
    PM->>EventBus: emitPlugin('plugin:loaded', {name, version})
    
    Note over Discord,EventBus: Runtime: Discord events flow
    Discord->>PM: emit(eventName, data)
    PM->>EventBus: emitDiscord(eventName, data)
    EventBus->>Plugin: trigger event handlers
    
    Note over Main,PM: Shutdown sequence
    Main->>Main: shutdownRateLimiter()
    Main->>PM: unloadAll()
    PM->>EventBus: unsubscribe all subscriptions
    PM->>Plugin: onUnload()
    PM->>EventBus: emitPlugin('plugin:unloaded', {name})
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7512c and 5ab8788.

📒 Files selected for processing (6)
  • src/api/routes/messages.ts (1 hunks)
  • src/discord/events/index.ts (3 hunks)
  • src/index.ts (2 hunks)
  • src/plugins/manager.ts (1 hunks)
  • src/plugins/sdk.ts (1 hunks)
  • src/types/plugin.types.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/types/plugin.types.ts (1)
src/plugins/sdk.ts (1)
  • EventHelpers (173-173)
src/discord/events/index.ts (1)
src/discord/serializers.ts (2)
  • serializeUser (67-79)
  • serializeScheduledEvent (441-466)
src/index.ts (1)
src/api/middleware/rateLimit.ts (1)
  • shutdownRateLimiter (156-162)
🔇 Additional comments (7)
src/index.ts (1)

5-5: LGTM! Proper resource cleanup during shutdown.

The rate limiter cleanup correctly clears intervals and the rate limit store. The shutdown order is appropriate—cleaning up the rate limiter before unloading plugins and exiting.

Also applies to: 48-49

src/plugins/manager.ts (1)

217-219: LGTM! Cleaner alternative to non-null assertion.

The cast is safe since pluginSubRouter is guaranteed non-null within the if (plugin.routes) block where it was initialized at line 173. This refactor improves readability.

src/discord/events/index.ts (2)

269-281: LGTM! Safe type assertion with partial check.

The type assertion is appropriately guarded by checking oldUser.partial === false before serializing.


608-622: The type assertion on newEvent is safe given the current configuration.

Since Partials.GuildScheduledEvent is not enabled in the client configuration (src/discord/client.ts:39-46), Discord.js guarantees that newEvent will never be partial in guildScheduledEventUpdate events. The cast on line 619 is valid. However, if Partials.GuildScheduledEvent is ever added to the client config in the future, this code would break—serializeScheduledEvent accesses properties (e.g., event.coverImageURL() on line 463) that would be undefined on partial objects. Consider adding an explicit .partial check for consistency with oldEvent and future-proofing against configuration changes.

src/plugins/sdk.ts (1)

170-173: LGTM! Proper type export for public API.

Exporting EventHelpers as a type alias enables consistent typing across the codebase and provides a stable public API for plugin authors.

src/api/routes/messages.ts (1)

5-22: LGTM! Improved type safety with clear documentation.

The MessageParams interface and updated getParams helper provide better type safety. The JSDoc comment clearly explains that channelId is merged from the parent router via mergeParams: true, which justifies the empty string fallback.

src/types/plugin.types.ts (1)

12-12: LGTM! Type consolidation improves consistency.

Replacing the inline helpers object type with the EventHelpers type exported from src/plugins/sdk.ts centralizes the type definition and ensures consistency across the plugin API surface.

Also applies to: 94-97

Comment thread src/discord/events/index.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/types/events.types.ts (1)

563-574: Union type for partial scheduled-event deletes looks correct; document consumer expectations.

The SerializedScheduledEvent | { id; guildId; partial: true } union cleanly models the new minimal delete payload and aligns with the broadcaster. It’s a breaking type tightening for consumers expecting full data on guildScheduledEventDelete, so it’s worth calling out in plugin/client docs so they always branch on partial === true before accessing other fields.

src/discord/events/index.ts (2)

269-281: userUpdate: partial guard + typed serialization is sound.

The oldUser.partial ? null : serializeUser(oldUser as User) pattern is consistent with your other partial handling and keeps serializeUser on fully-hydrated instances only. Looks good.


608-621: guildScheduledEventUpdate typing improvements are correct and consistent.

Guarding oldEvent with !oldEvent.partial before serializing and asserting GuildScheduledEvent matches the serializer’s expectations and mirrors your userUpdate pattern. If you ever see partial newEvents in practice, you might later mirror that guard for symmetry, but current logic is fine.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ab8788 and d34f319.

📒 Files selected for processing (2)
  • src/discord/events/index.ts (3 hunks)
  • src/types/events.types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/types/events.types.ts (1)
src/types/discord.types.ts (1)
  • SerializedScheduledEvent (243-266)
src/discord/events/index.ts (2)
src/discord/serializers.ts (2)
  • serializeUser (67-79)
  • serializeScheduledEvent (441-466)
src/discord/client.ts (1)
  • discordClient (9-47)
🔇 Additional comments (2)
src/discord/events/index.ts (2)

1-2: Type-only discord.js imports are appropriate here.

Using import type { User, GuildScheduledEvent } keeps these as purely compile-time aids and matches their usage in later assertions, so no runtime behavior change.


624-645: Partial scheduled-event delete handling correctly fixes the previous bug.

Short-circuiting on event.partial and broadcasting only { id, guildId, partial: true } avoids unsafe calls into serializeScheduledEvent on incomplete data, and the non-partial path still serializes the full GuildScheduledEvent. This aligns with the updated GuildScheduledEventDeleteEvent.data union and resolves the earlier critical issue around delete handling.

@Coder-soft Coder-soft merged commit 22eebe3 into master Dec 8, 2025
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant