supports more env variables
This commit is contained in:
parent
0eb9167178
commit
ba77cc0e28
3 changed files with 38 additions and 8 deletions
22
bot/main.go
22
bot/main.go
|
@ -3,6 +3,7 @@ package bot
|
|||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
botHandlers "govd/bot/handlers"
|
||||
|
@ -33,12 +34,29 @@ func Start() {
|
|||
if err != nil {
|
||||
log.Fatalf("failed to create bot: %v", err)
|
||||
}
|
||||
concurrentUpdates, err := strconv.Atoi(os.Getenv("CONCURRENT_UPDATES"))
|
||||
if err != nil {
|
||||
log.Println("failed to parse CONCURRENT_UPDATES env, using 50")
|
||||
concurrentUpdates = 50
|
||||
}
|
||||
logDispatcherErrors, err := strconv.ParseBool(os.Getenv("LOG_DISPATCHER_ERRORS"))
|
||||
if err != nil {
|
||||
log.Println("failed to parse LOG_ERRORS env, using false")
|
||||
logDispatcherErrors = false
|
||||
}
|
||||
dispatcher := ext.NewDispatcher(&ext.DispatcherOpts{
|
||||
Error: func(b *gotgbot.Bot, ctx *ext.Context, err error) ext.DispatcherAction {
|
||||
// log.Println("an error occurred while handling update:", err.Error())
|
||||
if logDispatcherErrors {
|
||||
log.Printf("an error occurred while handling update: %v", err)
|
||||
}
|
||||
return ext.DispatcherActionNoop
|
||||
},
|
||||
MaxRoutines: 500,
|
||||
Panic: func(b *gotgbot.Bot, ctx *ext.Context, r interface{}) {
|
||||
if logDispatcherErrors {
|
||||
log.Printf("panic occurred while handling update: %v", r)
|
||||
}
|
||||
},
|
||||
MaxRoutines: concurrentUpdates,
|
||||
})
|
||||
updater := ext.NewUpdater(dispatcher, nil)
|
||||
registerHandlers(dispatcher)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue