Skip to content

Commit

Permalink
Fix issues in custom ignoring algorithm
Browse files Browse the repository at this point in the history
Signed-off-by: aliwoto <aminnimaj@gmail.com>
  • Loading branch information
ALiwoto committed Nov 9, 2021
1 parent febf518 commit 9fc189d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ratelimiter/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (l *Limiter) limiterHandler(b *gotgbot.Bot, ctx *ext.Context) error {
status.count++
l.userMap[id] = status
l.mutex.Unlock()
if status.IsCustomLimited() {
if !status.custom.ignoreException && l.isException(ctx.Message) {
return ext.ContinueGroups
}
return ext.EndGroups
}
return ext.ContinueGroups
}

Expand Down
8 changes: 6 additions & 2 deletions ratelimiter/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (l *Limiter) checker() {

l.mutex.Lock()
for key, value := range l.userMap {
if value == nil || time.Since(value.Last) > l.timeout {
if value == nil || value.canBeDeleted(l) {
delete(l.userMap, key)
}
}
Expand All @@ -400,12 +400,16 @@ func (s *UserStatus) IsCustomLimited() bool {
return false
}

if time.Since(s.custom.startTime) > s.custom.duration {
if time.Since(s.custom.startTime) > s.custom.duration && s.custom.duration != 0 {
s.custom = nil
return false
}

return true
}

func (s *UserStatus) canBeDeleted(l *Limiter) bool {
return time.Since(s.Last) > l.timeout && !s.limited && !s.IsCustomLimited()
}

//---------------------------------------------------------

0 comments on commit 9fc189d

Please sign in to comment.