Skip to content

Commit

Permalink
Fix nil pointer on flood error
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Mar 22, 2022
1 parent 74c1100 commit 77132c3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions handler/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (h Handler) sendText(subscriber int64, text string, sendOptions *telebot.Se
_, err := h.Bot.Send(telebot.ChatID(subscriber), text, sendOptions)

var telebotError *telebot.Error
var floodError *telebot.FloodError

if err != nil {
if errors.Is(err, telebot.ErrChatNotFound) {
Expand All @@ -146,8 +145,8 @@ func (h Handler) sendText(subscriber int64, text string, sendOptions *telebot.Se
h.DB.Subscribers.Delete(subscriber)
h.DB.Subscribers.Create(migratedTo)
return h.sendText(migratedTo, text, sendOptions)
} else if errors.As(err, floodError) {
retryAfter := floodError.RetryAfter
} else if errors.As(err, &telebot.FloodError{}) {
retryAfter := err.(telebot.FloodError).RetryAfter
log.Printf("%d: Flood error, retrying after: %d seconds", subscriber, retryAfter)
time.Sleep(time.Duration(retryAfter) * time.Second)
h.sendText(subscriber, text, sendOptions)
Expand Down

0 comments on commit 77132c3

Please sign in to comment.