Style and security

This commit is contained in:
HugeFrog24
2026-03-05 04:50:36 +01:00
parent d8d0da4704
commit 44fcd02d9a
30 changed files with 3407 additions and 321 deletions
Executable → Regular
+8 -2
View File
@@ -50,8 +50,14 @@ func (b *Bot) checkRateLimits(userID int64) bool {
limiter.lastDailyReset = now
}
// Check if the message exceeds rate limits
if !limiter.hourlyLimiter.Allow() || !limiter.dailyLimiter.Allow() {
// Check if the message exceeds rate limits.
// Reserve from both limiters first, then cancel both if either is over budget.
// This prevents consuming a token from one limiter when the other rejects.
dailyRes := limiter.dailyLimiter.ReserveN(now, 1)
hourlyRes := limiter.hourlyLimiter.ReserveN(now, 1)
if dailyRes.DelayFrom(now) > 0 || hourlyRes.DelayFrom(now) > 0 {
dailyRes.CancelAt(now)
hourlyRes.CancelAt(now)
banDuration, err := time.ParseDuration(b.config.TempBanDuration)
if err != nil {
// If parsing fails, default to a 24-hour ban