Skip to content

add: update when counter with 10 minutes cooldown globally - #5

Open
isotjs wants to merge 2 commits into
MetrolistGroup:mainfrom
isotjs:add/release-counter
Open

add: update when counter with 10 minutes cooldown globally#5
isotjs wants to merge 2 commits into
MetrolistGroup:mainfrom
isotjs:add/release-counter

Conversation

@isotjs

@isotjs isotjs commented Jun 17, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Added a release-date question counter.
    • Release-date questions now automatically increment the counter.
    • Added /counter commands in Discord and Telegram to view the current count.
    • Counter values persist across restarts and are protected by a cooldown to prevent rapid duplicate increments.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7f61cb1-be4b-4617-80be-a92a6b1eb186

📥 Commits

Reviewing files that changed from the base of the PR and between 9ba70ca and b7e600e.

📒 Files selected for processing (7)
  • cmd/release_counter.go
  • db/db.go
  • discord/bot.go
  • discord/handlers.go
  • main.go
  • telegram/bot.go
  • telegram/handlers.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ramazansancar

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 win

Release question check can intercept moderation commands in both Discord and Telegram handlers. The MatchReleaseQuestion check runs before the moderation command pattern check in both handlers, and the regex can match !-prefixed messages (e.g., !ban @user when 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 calling cmd.MatchReleaseQuestion.
  • telegram/handlers.go#L44-55: Apply the same !strings.HasPrefix(content, "!") guard before calling cmd.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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ba70ca and b7e600e.

📒 Files selected for processing (7)
  • cmd/release_counter.go
  • db/db.go
  • discord/bot.go
  • discord/handlers.go
  • main.go
  • telegram/bot.go
  • telegram/handlers.go

Comment thread cmd/release_counter.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)` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
`|(\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.

Comment thread cmd/release_counter.go
Comment on lines +36 to +42
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 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.

Suggested change
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.

Comment thread discord/handlers.go
Comment on lines +116 to +127
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
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
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.

Comment thread telegram/handlers.go
Comment on lines +44 to +55
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
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
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.

@isotjs

isotjs commented Jul 13, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

Öylesine bir PR 😄 belki kullanılır diye açık tutuyorum 😃

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@isotjs Anlaşıldı, PR açık kalsın 😊 İhtiyaç olduğunda kullanılabilir, hazır bekliyor. İncelemem tamamlandı, ek değişiklik ya da inceleme istediğinizde haber verin.

ᕦ(ò_óˇ)ᕤ

@ramazansancar

Copy link
Copy Markdown

@coderabbitai review

Öylesine bir PR 😄 belki kullanılır diye açık tutuyorum 😃

Her geliştirmenin faydası olur :)
Burada türk geliştiriciler görmek güzel 😎🙌

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@ramazansancar Katılıyorum, her katkı değerlidir 🙌 Türkiye'den geliştiricilerle bu şekilde etkileşimde bulunmak güzel. PR'da ihtiyacınız olduğunda incelemek için buradayım, sadece haber verin!

(=^・ω・^=)

@isotjs

isotjs commented Jul 13, 2026

Copy link
Copy Markdown
Author

@ramazansancar (ai'ı pinglemeyeyim çok konuşuyor 😃) Teşekkürler deniyoruz bir şeyler 😁

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.

2 participants