[Reviewed] feat: Add cooldown tracking with Collection (Item 5) - NEEDS REVISION#51
Open
messiawrq-spec wants to merge 1 commit into
Open
[Reviewed] feat: Add cooldown tracking with Collection (Item 5) - NEEDS REVISION#51messiawrq-spec wants to merge 1 commit into
messiawrq-spec wants to merge 1 commit into
Conversation
Resolves Item IN3PIRE#5 from Issue IN3PIRE#40. Added a cooldown `Collection` logic into `interactionCreate.js` to prevent command spam based on a configured `command.cooldown` (defaults to 3s).
TrivCodez
requested changes
May 15, 2026
Contributor
TrivCodez
left a comment
There was a problem hiding this comment.
Summary
Adds in-memory cooldown tracking with Discord.js Collection for per-command rate limiting.
🔴 Critical Issues
| File | Line | Severity | Issue | Fix |
|---|---|---|---|---|
src/events/interactionCreate.js |
4-26 | CRITICAL | Duplicate cooldown logic - This PR implements cooldown directly but the file already imports and uses checkCooldown/setCooldown from ../utils/cooldown |
Remove lines 14-33 entirely - the existing checkCooldown call at line 35 already handles this |
🟡 Warnings
| File | Line | Severity | Issue | Fix |
|---|---|---|---|---|
src/events/interactionCreate.js |
4-5 | High | Imports Collection and creates cooldowns but duplicates existing utility |
Delete import and use existing cooldown module |
src/events/interactionCreate.js |
20 | Medium | Hardcoded defaultCooldownDuration = 3 - magic number |
Move to config or command-level setting |
src/events/interactionCreate.js |
37 | Low | Cooldown check happens AFTER this implementation runs (line 35) causing redundant logic | Remove duplicate implementation |
Analysis
This PR creates conflicting cooldown implementations:
- Lines 14-33: New in-memory cooldown with Collection
- Line 35: Calls existing
checkCooldown()from utility module
Problem: Both will run, potentially causing:
- Double cooldown enforcement
- Memory leak (Collection grows unbounded)
- Confusing behavior for command authors
🟢 Suggestions
Option 1 (Recommended): Remove this PR entirely - existing cooldown.js handles it
Option 2: Replace cooldown.js with this implementation if Collection-based approach is preferred
Option 3: Merge both approaches - use Collection for storage but keep utility functions for logic
✅ Good
- Clean Discord timestamp format for remaining time
- Proper cleanup with
setTimeout - Per-command customization support
Needs revision - Must resolve duplicate cooldown logic before merging. Recommend removing lines 14-33 and keeping existing checkCooldown/setCooldown calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claims and resolves Item #5 from Issue #40.
Added a comprehensive cooldown manager directly inside
interactionCreate.js. It utilizes standard Discord.jsCollectionobjects to track users per-command, honoring customcommand.cooldownparameters and protecting against spam.