This commit is contained in:
@@ -3,7 +3,9 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -16,6 +18,7 @@ type Config struct {
|
||||
AdminRoleIDs []string
|
||||
TeamRoleIDs []string
|
||||
DatabasePath string
|
||||
ThreadDeleteAfter time.Duration
|
||||
}
|
||||
|
||||
func loadConfig() Config {
|
||||
@@ -29,6 +32,7 @@ func loadConfig() Config {
|
||||
AdminRoleIDs: splitCSV(os.Getenv("DISCORD_ADMIN_ROLE_IDS")),
|
||||
TeamRoleIDs: splitCSV(os.Getenv("DISCORD_TEAM_ROLE_IDS")),
|
||||
DatabasePath: getenv("DATABASE_PATH", "orders.db"),
|
||||
ThreadDeleteAfter: durationHoursEnv("THREAD_DELETE_AFTER_HOURS", 72),
|
||||
}
|
||||
if cfg.Token == "" || cfg.AppID == "" || cfg.InternalOrderChannelID == "" {
|
||||
log.Fatal("Bitte DISCORD_TOKEN, DISCORD_APP_ID und DISCORD_INTERNAL_ORDER_CHANNEL_ID setzen")
|
||||
@@ -56,3 +60,16 @@ func splitCSV(v string) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func durationHoursEnv(key string, fallbackHours int) time.Duration {
|
||||
v := strings.TrimSpace(os.Getenv(key))
|
||||
if v == "" {
|
||||
return time.Duration(fallbackHours) * time.Hour
|
||||
}
|
||||
hours, err := strconv.Atoi(v)
|
||||
if err != nil || hours < 0 {
|
||||
log.Printf("WARNUNG: %s ist ungültig, verwende %d Stunden", key, fallbackHours)
|
||||
return time.Duration(fallbackHours) * time.Hour
|
||||
}
|
||||
return time.Duration(hours) * time.Hour
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user