add: update when counter with 10 minutes cooldown globally - #5
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
discord/handlers.go (1)
1-1: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRelease question check can intercept moderation commands in both Discord and Telegram handlers. The
MatchReleaseQuestioncheck runs before the moderation command pattern check in both handlers, and the regex can match!-prefixed messages (e.g.,!ban@userwhen will you release), causing the moderation action to be silently skipped.
discord/handlers.go#L116-127: Guard the release question check with!strings.HasPrefix(content, "!")before callingcmd.MatchReleaseQuestion.telegram/handlers.go#L44-55: Apply the same!strings.HasPrefix(content, "!")guard before callingcmd.MatchReleaseQuestion.🤖 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 `@discord/handlers.go` at line 1, Guard the MatchReleaseQuestion checks in both Discord and Telegram handlers with !strings.HasPrefix(content, "!") before invoking them, so !-prefixed moderation commands continue to reach their command pattern handling. Update the relevant handler branches while preserving existing release-question behavior for non-command messages.
🤖 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 `@cmd/release_counter.go`:
- Line 25: Update the release-detection regex in the pattern construction around
`when will you` so that alternative only matches when paired with a
release-related keyword, consistent with the other alternatives. Preserve
legitimate release-counting matches while excluding unrelated phrases such as
questions about returning or responding.
- Around line 36-42: Update ReleaseCounterHandler.Increment to hold h.mu
continuously from the cooldown check through the database increment and
lastTriggeredAt update, releasing it only after the entire operation completes.
Preserve the existing early return for active cooldowns and ensure both Discord
and Telegram calls are serialized through the shared handler.
In `@discord/handlers.go`:
- Around line 116-127: Update the release-question handling in the Discord and
Telegram handlers to bypass MatchReleaseQuestion for messages prefixed with “!”.
Ensure such messages continue to the chatModPattern moderation check, while
preserving the existing release-counter behavior for non-command messages.
In `@telegram/handlers.go`:
- Around line 44-55: Update the MatchReleaseQuestion handling in the Telegram
message flow to skip messages beginning with “!” so moderation commands reach
the chatModPattern check. Preserve the existing release-counter and public-reply
behavior for non-command messages, and leave moderation handling unchanged.
---
Outside diff comments:
In `@discord/handlers.go`:
- Line 1: Guard the MatchReleaseQuestion checks in both Discord and Telegram
handlers with !strings.HasPrefix(content, "!") before invoking them, so
!-prefixed moderation commands continue to reach their command pattern handling.
Update the relevant handler branches while preserving existing release-question
behavior for non-command messages.
🪄 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
Run ID: a7f61cb1-be4b-4617-80be-a92a6b1eb186
📒 Files selected for processing (7)
cmd/release_counter.godb/db.godiscord/bot.godiscord/handlers.gomain.gotelegram/bot.gotelegram/handlers.go
| `|(\bis\s+there\s+a\s+(?:new\s+)?(?:update|release|version)\b)` + | ||
| `|(\bwhat'?s\s+the\s+(?:eta|status|release\s+date)\b)` + | ||
| `|(\b(?:update|release|version)\s+when\b)` + | ||
| `|(\bwhen\s+will\s+you\b)` + |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Regex alternative \bwhen\s+will\s+you\b is too broad.
This pattern matches any "when will you" phrase regardless of context — e.g., "when will you be back?" or "when will you respond?" — producing false positives that inflate the counter. All other alternatives require a release-related keyword; this one does not.
🐛 Proposed fix: require a release-related keyword
- `|(\bwhen\s+will\s+you\b)` +
+ `|(\bwhen\s+will\s+you\b[^.]{0,80}\b(?:update|release|version|app)\b)` +📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `|(\bwhen\s+will\s+you\b)` + | |
| `|(\bwhen\s+will\s+you\b[^.]{0,80}\b(?:update|release|version|app)\b)` + |
🤖 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 `@cmd/release_counter.go` at line 25, Update the release-detection regex in the
pattern construction around `when will you` so that alternative only matches
when paired with a release-related keyword, consistent with the other
alternatives. Preserve legitimate release-counting matches while excluding
unrelated phrases such as questions about returning or responding.
| func (h *ReleaseCounterHandler) Increment(isTelegram bool) (string, error) { | ||
| h.mu.Lock() | ||
| if time.Since(h.lastTriggeredAt) < releaseCooldown { | ||
| h.mu.Unlock() | ||
| return "", nil | ||
| } | ||
| h.mu.Unlock() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Race condition allows cooldown bypass.
The mutex is released between the cooldown check (line 38) and the DB increment (line 44). Two concurrent message handlers can both pass the cooldown check before either sets lastTriggeredAt, causing multiple counter increments within the 10-minute window. Since both Discord and Telegram share the same handler instance, cross-platform concurrent messages can trigger this.
🔒 Proposed fix: hold the lock for the entire operation
func (h *ReleaseCounterHandler) Increment(isTelegram bool) (string, error) {
h.mu.Lock()
+ defer h.mu.Unlock()
+
if time.Since(h.lastTriggeredAt) < releaseCooldown {
- h.mu.Unlock()
return "", nil
}
- h.mu.Unlock()
count, err := h.DB.IncrementReleaseCounter()
if err != nil {
return "", fmt.Errorf("incrementing release counter: %w", err)
}
- h.mu.Lock()
h.lastTriggeredAt = time.Now()
- h.mu.Unlock()
return formatCounter(count, isTelegram), nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (h *ReleaseCounterHandler) Increment(isTelegram bool) (string, error) { | |
| h.mu.Lock() | |
| if time.Since(h.lastTriggeredAt) < releaseCooldown { | |
| h.mu.Unlock() | |
| return "", nil | |
| } | |
| h.mu.Unlock() | |
| func (h *ReleaseCounterHandler) Increment(isTelegram bool) (string, error) { | |
| h.mu.Lock() | |
| defer h.mu.Unlock() | |
| if time.Since(h.lastTriggeredAt) < releaseCooldown { | |
| return "", nil | |
| } | |
| count, err := h.DB.IncrementReleaseCounter() | |
| if err != nil { | |
| return "", fmt.Errorf("incrementing release counter: %w", err) | |
| } | |
| h.lastTriggeredAt = time.Now() | |
| return formatCounter(count, isTelegram), nil | |
| } |
🤖 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 `@cmd/release_counter.go` around lines 36 - 42, Update
ReleaseCounterHandler.Increment to hold h.mu continuously from the cooldown
check through the database increment and lastTriggeredAt update, releasing it
only after the entire operation completes. Preserve the existing early return
for active cooldowns and ensure both Discord and Telegram calls are serialized
through the shared handler.
| if cmd.MatchReleaseQuestion(content) { | ||
| text, err := b.ReleaseCounter.Increment(false) | ||
| if err != nil { | ||
| b.Logger.Error("release counter error", zap.Error(err)) | ||
| return | ||
| } | ||
| if text == "" { | ||
| return | ||
| } | ||
| sendReply(s, m.ChannelID, m.ID, text, false, b.Logger) | ||
| return | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Release question check can intercept moderation commands.
The MatchReleaseQuestion check runs before the chatModPattern check (line 129). Since the regex matches any "when will you" phrase, a message like !ban @user when will you release would be intercepted by the release counter handler, silently skipping the ban. This affects both Discord and Telegram handlers.
🐛 Proposed fix: skip `!`-prefixed messages
- if cmd.MatchReleaseQuestion(content) {
+ if !strings.HasPrefix(content, "!") && cmd.MatchReleaseQuestion(content) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if cmd.MatchReleaseQuestion(content) { | |
| text, err := b.ReleaseCounter.Increment(false) | |
| if err != nil { | |
| b.Logger.Error("release counter error", zap.Error(err)) | |
| return | |
| } | |
| if text == "" { | |
| return | |
| } | |
| sendReply(s, m.ChannelID, m.ID, text, false, b.Logger) | |
| return | |
| } | |
| if !strings.HasPrefix(content, "!") && cmd.MatchReleaseQuestion(content) { | |
| text, err := b.ReleaseCounter.Increment(false) | |
| if err != nil { | |
| b.Logger.Error("release counter error", zap.Error(err)) | |
| return | |
| } | |
| if text == "" { | |
| return | |
| } | |
| sendReply(s, m.ChannelID, m.ID, text, false, b.Logger) | |
| return | |
| } |
🤖 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 `@discord/handlers.go` around lines 116 - 127, Update the release-question
handling in the Discord and Telegram handlers to bypass MatchReleaseQuestion for
messages prefixed with “!”. Ensure such messages continue to the chatModPattern
moderation check, while preserving the existing release-counter behavior for
non-command messages.
| if cmd.MatchReleaseQuestion(content) { | ||
| text, err := b.ReleaseCounter.Increment(true) | ||
| if err != nil { | ||
| b.Logger.Error("release counter error", zap.Error(err)) | ||
| return | ||
| } | ||
| if text == "" { | ||
| return | ||
| } | ||
| sendPublicReply(b.API, msg.Chat.ID, msg.MessageID, text, "", false, b.Logger) | ||
| return | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Release question check can intercept moderation commands (same as Discord).
The MatchReleaseQuestion check runs before the chatModPattern check (line 57). A !-prefixed moderation command containing "when will you" would be intercepted, silently skipping the moderation action.
🐛 Proposed fix: skip `!`-prefixed messages
- if cmd.MatchReleaseQuestion(content) {
+ if !strings.HasPrefix(content, "!") && cmd.MatchReleaseQuestion(content) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if cmd.MatchReleaseQuestion(content) { | |
| text, err := b.ReleaseCounter.Increment(true) | |
| if err != nil { | |
| b.Logger.Error("release counter error", zap.Error(err)) | |
| return | |
| } | |
| if text == "" { | |
| return | |
| } | |
| sendPublicReply(b.API, msg.Chat.ID, msg.MessageID, text, "", false, b.Logger) | |
| return | |
| } | |
| if !strings.HasPrefix(content, "!") && cmd.MatchReleaseQuestion(content) { | |
| text, err := b.ReleaseCounter.Increment(true) | |
| if err != nil { | |
| b.Logger.Error("release counter error", zap.Error(err)) | |
| return | |
| } | |
| if text == "" { | |
| return | |
| } | |
| sendPublicReply(b.API, msg.Chat.ID, msg.MessageID, text, "", false, b.Logger) | |
| return | |
| } |
🤖 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 `@telegram/handlers.go` around lines 44 - 55, Update the MatchReleaseQuestion
handling in the Telegram message flow to skip messages beginning with “!” so
moderation commands reach the chatModPattern check. Preserve the existing
release-counter and public-reply behavior for non-command messages, and leave
moderation handling unchanged.
Öylesine bir PR 😄 belki kullanılır diye açık tutuyorum 😃 |
|
Tip For best results, initiate chat on the files or code changes.
ᕦ(ò_óˇ)ᕤ |
Her geliştirmenin faydası olur :) |
|
Tip For best results, initiate chat on the files or code changes.
(=^・ω・^=) |
|
@ramazansancar (ai'ı pinglemeyeyim çok konuşuyor 😃) Teşekkürler deniyoruz bir şeyler 😁 |
Summary by CodeRabbit
/countercommands in Discord and Telegram to view the current count.