supports more env variables
This commit is contained in:
parent
0eb9167178
commit
ba77cc0e28
3 changed files with 38 additions and 8 deletions
18
.env.example
18
.env.example
|
@ -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
|
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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue