should not panic in production env

bot-api-6.1
Jqs7 2015-06-30 00:04:48 +08:00
parent 7b9b7856fc
commit f6cf1bb782
1 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,10 @@
package tgbotapi package tgbotapi
import (
"log"
"time"
)
// UpdatesChan returns a chan that is called whenever a new message is gotten. // UpdatesChan returns a chan that is called whenever a new message is gotten.
func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
bot.Updates = make(chan Update, 100) bot.Updates = make(chan Update, 100)
@ -8,15 +13,22 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
for { for {
updates, err := bot.GetUpdates(config) updates, err := bot.GetUpdates(config)
if err != nil { if err != nil {
panic(err) if bot.Debug == true {
} panic(err)
} else {
for _, update := range updates { log.Println(err)
if update.UpdateID >= config.Offset { log.Println("Retry in 3 Seconds")
config.Offset = update.UpdateID + 1 time.Sleep(time.Second * 3)
bot.Updates <- update }
} else {
for _, update := range updates {
if update.UpdateID >= config.Offset {
config.Offset = update.UpdateID + 1
bot.Updates <- update
}
} }
} }
} }
}() }()