supports more env variables

This commit is contained in:
stefanodvx 2025-04-15 18:44:01 +02:00
parent 0eb9167178
commit ba77cc0e28
3 changed files with 38 additions and 8 deletions

View file

@ -1,15 +1,23 @@
BOT_API_URL=https://api.telegram.org
BOT_TOKEN=12345678:ABC-DEF1234ghIkl-zyx57W2P0s
# database
DB_HOST=localhost
DB_PORT=3306
DB_NAME=govd
DB_USER=govd
DB_PASSWORD=password
REPO_URL=https://github.com/govdbot/govd
# gotgbot
BOT_API_URL=https://api.telegram.org
BOT_TOKEN=12345678:ABC-DEF1234ghIkl-zyx57W2P0s
CONCURRENT_UPDATES=-1
LOG_ERRORS=0
# downloads
DOWNLOADS_DIR=downloads
# proxy
HTTP_PROXY=
HTTPS_PROXY=
NO_PROXY=
NO_PROXY=
# misc
REPO_URL=https://github.com/govdbot/govd

View file

@ -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)

View file

@ -21,11 +21,15 @@ import (
)
func DefaultConfig() *models.DownloadConfig {
downloadsDir := os.Getenv("DOWNLOADS_DIR")
if downloadsDir == "" {
downloadsDir = "downloads"
}
return &models.DownloadConfig{
ChunkSize: 10 * 1024 * 1024, // 10MB
Concurrency: 4,
Timeout: 30 * time.Second,
DownloadDir: "downloads",
DownloadDir: downloadsDir,
RetryAttempts: 3,
RetryDelay: 2 * time.Second,
Remux: true,