Added booster fixes & db cleanups#11
Conversation
|
Warning Review limit reached
More reviews will be available in 44 minutes and 54 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR adds startup loading for scheduled loop modules, introduces a booster cleanup loop, updates booster command checks and boost registration handling, bumps the package version, and expands ChangesBooster lifecycle and loop loading
Sequence Diagram(s)Loop startup and scheduled cleanup sequenceDiagram
participant Index as src/index.ts
participant LoadCommands as loadCommands()
participant LoadLoops as loadLoops()
participant Interval as setInterval
participant CleanupLoop as src/loops/boosterCleanup.ts
participant Prisma as prisma.booster.deleteMany
Index->>LoadCommands: await
Index->>LoadLoops: await
LoadLoops->>CleanupLoop: import default export
LoadLoops->>Interval: schedule execute() every runEvery seconds
Interval->>CleanupLoop: execute()
CleanupLoop->>Prisma: deleteMany where boostCounts < 1
Booster subcommand flow sequenceDiagram
participant Interaction as Discord interaction
participant Booster as booster command
participant Fetch as members.fetch(...)
participant GetBooster as getBooster(...)
participant RemoveBoost as removeBoost(...)
participant RegisterBoost as registerBoost(...)
participant AddBoostCount as addBoostCount(...)
Interaction->>Booster: run /booster subcommand
Booster->>Fetch: fetch target member
alt check
Booster->>GetBooster: read booster record
alt boostCounts == 0
Booster->>RemoveBoost: clean up stored record
end
else add
Booster->>RegisterBoost: register boost
Booster->>AddBoostCount: increment count
end
Booster-->>Interaction: ephemeral reply
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/commands/booster.ts (1)
138-140: 🎯 Functional Correctness | 🟠 MajorMake the initial defer ephemeral.
TheseeditReply({ flags: MessageFlags.Ephemeral ... })calls won’t change a publicdeferReply()into an ephemeral response. SetMessageFlags.Ephemeralon the matchingdeferReply()instead; the same applies to the othereditReplycalls below.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/booster.ts` around lines 138 - 140, The Booster command is trying to make responses ephemeral in editReply, but that cannot change the visibility after deferReply has already been sent publicly. Update the matching deferReply call in booster.ts to include MessageFlags.Ephemeral, and remove the Ephemeral flag from the related editReply calls so the response flow stays consistent; use the deferReply and editReply paths in the Booster interaction handler as the main places to adjust.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.gitignore:
- Around line 6-7: The ignore patterns in the .gitignore entries for
src/commands/*.make.ts and src/events/*.make.ts include trailing spaces, so
remove those extra spaces to ensure the patterns match correctly. Update the
.gitignore entries directly and keep the two patterns exact with no whitespace
after them.
In `@src/commands/booster.ts`:
- Around line 183-204: The booster embed in booster.ts currently formats the
“Boosting since” field using member!.premiumSince!, which can throw when the
member is missing or no longer boosting. Update the logic around the embed
creation in the command handler to guard premiumSince before calling getTime(),
and only render the timestamp when a valid premiumSince value exists. If the
member or premiumSince is unavailable, fall back to a safe display value instead
of dereferencing the non-null assertions.
- Around line 147-150: The cleanup call in booster handling is not being
awaited, so rejected errors escape the surrounding try/catch and stale state can
remain. Update the logic in the booster command flow around `removeBoost` to
await the promise before continuing, keeping the existing error handling in
place so failures are caught by this handler.
- Around line 231-238: The boost flow in registerBoost and addBoostCount is
double-counting boosts by applying the increment twice. Update the booster
handling in the booster command so that registerBoost remains responsible for
creating or incrementing the boost record, and avoid calling addBoostCount with
amount afterward when it would add the same boost again; instead, keep a single
source of truth for the boost increment in the addBoost path.
In `@src/libs/loops.ts`:
- Around line 27-28: Wrap the per-file dynamic import in loadLoops so a bad loop
module does not abort startup: the import at fileInfo loading should be inside a
try/catch for each file, log the failure with the file name and error details,
and then continue to the next loop. Keep the per-loop validation and
registration flow in src/libs/loops.ts intact, but ensure one import failure
cannot escape loadLoops and prevent src/index.ts from completing boot.
- Around line 36-45: The async loop in the run function can overlap because
setInterval schedules a new execution before the previous fileInfo.execute()
finishes. Update the looping logic in run and the setInterval scheduling so only
one execution can run at a time, either by adding a running guard around
fileInfo.execute() or by replacing setInterval with self-scheduling setTimeout
after each completion. Keep the logging in logger.error unchanged except for
ensuring the guarded/scheduled flow still reports failures correctly.
---
Outside diff comments:
In `@src/commands/booster.ts`:
- Around line 138-140: The Booster command is trying to make responses ephemeral
in editReply, but that cannot change the visibility after deferReply has already
been sent publicly. Update the matching deferReply call in booster.ts to include
MessageFlags.Ephemeral, and remove the Ephemeral flag from the related editReply
calls so the response flow stays consistent; use the deferReply and editReply
paths in the Booster interaction handler as the main places to adjust.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 268049e0-cbde-4984-b893-d6483f87b5b6
📒 Files selected for processing (6)
.gitignorepackage.jsonsrc/commands/booster.tssrc/index.tssrc/libs/loops.tssrc/loops/boosterCleanup.ts
🚀 Summary
✨ Features
loadLoops()startup support to discover and register loop scripts.boosterCleanuploop to delete booster entries with zeroboostCountsevery 60 seconds.🐛 Fixes
booster checknow verifies the target member’s active boosting status more accurately.booster addnow blocks non-boosting members from being added.booster checknow removes stale booster records whenboostCountsis zero and reports cleanup failures with a support link.♻️ Improvements
runEveryorexecutedefinitions.