should not panic in production env
parent
7b9b7856fc
commit
f6cf1bb782
14
updates.go
14
updates.go
|
@ -1,5 +1,10 @@
|
|||
package tgbotapi
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UpdatesChan returns a chan that is called whenever a new message is gotten.
|
||||
func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
||||
bot.Updates = make(chan Update, 100)
|
||||
|
@ -8,9 +13,14 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
|||
for {
|
||||
updates, err := bot.GetUpdates(config)
|
||||
if err != nil {
|
||||
if bot.Debug == true {
|
||||
panic(err)
|
||||
} else {
|
||||
log.Println(err)
|
||||
log.Println("Retry in 3 Seconds")
|
||||
time.Sleep(time.Second * 3)
|
||||
}
|
||||
|
||||
} else {
|
||||
for _, update := range updates {
|
||||
if update.UpdateID >= config.Offset {
|
||||
config.Offset = update.UpdateID + 1
|
||||
|
@ -18,6 +28,8 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
return bot.Updates, nil
|
||||
|
|
Loading…
Reference in New Issue