fix: rate limit behaviour for multi-channel spam - #86
Merged
Conversation
- Ensure rate limit uses are checked when EITHER messages haven't reached available uses, or the number of unique channels wasn't met
- Add tests for ratelimit class - Add cleanup method for ratelimit class setTimeout to allow test runner to exit gracefully - Update lint workflow to run tests in CI - remove redundant `consume` param
- Appease the linter and formatter
- Add unit tests
theetrain
marked this pull request as ready for review
July 27, 2026 04:43
theetrain
commented
Jul 27, 2026
Comment on lines
+77
to
+79
| get action(): SpamActionValues { | ||
| return SPAM_FILTER_MULTI_CHANNEL_ACTION ?? 'log'; | ||
| }, |
Collaborator
Author
There was a problem hiding this comment.
This entire file underwent a big refactor to be more config-based (and eventually, CMS-config-based).
One important change is here; to only log multi channel spam attempts rather than time out.
| channel_ids: channels.add(channelId), | ||
| }); | ||
| } | ||
| if (available_uses > 0 || channels.size < this.unique_channels) { |
Collaborator
Author
There was a problem hiding this comment.
And here's the important fix, from && to || so that unique channel checks can be made without short-circuiting.
theetrain
commented
Jul 27, 2026
| this.available_uses.delete(key); | ||
| }, this.time_period); | ||
|
|
||
| RateLimitStore.timers.push(timer); |
Collaborator
Author
There was a problem hiding this comment.
This will probably cause a memory leak.
Collaborator
Author
There was a problem hiding this comment.
theetrain
marked this pull request as draft
July 27, 2026 12:08
theetrain
marked this pull request as ready for review
July 27, 2026 14:22
ghostdevv
approved these changes
Aug 11, 2026
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.
Problem
discord-bot/src/utils/ratelimit.ts
Lines 33 to 41 in 3cf765e
discord-bot/src/events/on_message/_spam_filter.ts
Lines 96 to 103 in 3cf765e
Solution
Todos