Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: aliwoto <aminnimaj@gmail.com>
  • Loading branch information
ALiwoto committed Feb 2, 2022
1 parent 24c9620 commit b10cd97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</p>

> Name: Rate Limiter \
> Version: v1.0.6 \
> Version: v1.0.7 \
> Edit: 2 Feb 2021 \
> By: ALiwoto and Contributors (C)
Expand Down
6 changes: 3 additions & 3 deletions ratelimiter/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (l *Limiter) limiterHandler(b *gotgbot.Bot, ctx *ext.Context) error {
l.userMap[id] = status
l.mutex.Unlock()
if status.IsCustomLimited() {
if !status.custom.ignoreException && l.isException(ctx.Message) {
if !status.custom.ignoreException && l.isExceptionCtx(ctx) {
return ext.ContinueGroups
}
return ext.EndGroups
Expand Down Expand Up @@ -107,7 +107,7 @@ func (l *Limiter) limiterHandler(b *gotgbot.Bot, ctx *ext.Context) error {
status.count = 0
}

if !l.isException(ctx.Message) {
if !l.isExceptionCtx(ctx) {
status.count++
}

Expand All @@ -128,7 +128,7 @@ func (l *Limiter) limiterHandler(b *gotgbot.Bot, ctx *ext.Context) error {
status.Last = time.Now()

if status.IsCustomLimited() {
if !status.custom.ignoreException && l.isException(ctx.Message) {
if !status.custom.ignoreException && l.isExceptionCtx(ctx) {
return ext.ContinueGroups
}
return ext.EndGroups
Expand Down
11 changes: 9 additions & 2 deletions ratelimiter/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (l *Limiter) runTriggers(b *gotgbot.Bot, ctx *ext.Context) {
// it's id is in the exception list or not. This method's usage
// is internal-only.
func (l *Limiter) isException(msg *gotgbot.Message) bool {
if len(l.exceptionIDs) == 0 {
if len(l.exceptionIDs) == 0 || msg == nil {
return false
}

Expand All @@ -368,11 +368,18 @@ func (l *Limiter) isException(msg *gotgbot.Message) bool {
return false
}

func (l *Limiter) isExceptionCtx(ctx *ext.Context) bool {
if ctx.CallbackQuery != nil {
return l.isExceptionQuery(ctx.CallbackQuery)
}
return l.isException(ctx.Message)
}

// isException will check and see if msg can be ignored because
// it's id is in the exception list or not. This method's usage
// is internal-only.
func (l *Limiter) isExceptionQuery(cq *gotgbot.CallbackQuery) bool {
if len(l.exceptionIDs) == 0 {
if len(l.exceptionIDs) == 0 || cq == nil {
return false
}

Expand Down

0 comments on commit b10cd97

Please sign in to comment.