This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
type Config struct {
|
||||
// Discord settings
|
||||
DiscordToken string
|
||||
AdminIDs []string
|
||||
|
||||
// Himbucks settings
|
||||
HimbucksPerReward int
|
||||
@@ -36,6 +37,8 @@ type Config struct {
|
||||
HimbucksCooldown int
|
||||
HimboardCooldown int
|
||||
SendbucksCooldown int
|
||||
ShopCooldown int
|
||||
GivebucksCooldown int
|
||||
}
|
||||
|
||||
var AppConfig *Config
|
||||
@@ -45,6 +48,7 @@ func LoadConfig() *Config {
|
||||
config := &Config{
|
||||
// Discord settings
|
||||
DiscordToken: getEnv("DISCORD_TOKEN", ""),
|
||||
AdminIDs: getEnvSlice("ADMIN_USER_IDS", []string{}),
|
||||
|
||||
// Himbucks settings
|
||||
HimbucksPerReward: getEnvInt("HIMBUCKS_PER_REWARD", 10),
|
||||
@@ -71,6 +75,8 @@ func LoadConfig() *Config {
|
||||
HimbucksCooldown: getEnvInt("HIMBUCKS_COOLDOWN_SECONDS", 5),
|
||||
HimboardCooldown: getEnvInt("HIMBOARD_COOLDOWN_SECONDS", 5),
|
||||
SendbucksCooldown: getEnvInt("SENDBUCKS_COOLDOWN_SECONDS", 1800),
|
||||
ShopCooldown: getEnvInt("SHOP_COOLDOWN_SECONDS", 5),
|
||||
GivebucksCooldown: getEnvInt("GIVEBUCKS_COOLDOWN_SECONDS", 1),
|
||||
}
|
||||
|
||||
AppConfig = config
|
||||
@@ -93,4 +99,29 @@ func getEnvInt(key string, defaultValue int) int {
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
func getEnvSlice(key string, defaultValue []string) []string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return importStrings(value)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func importStrings(s string) []string {
|
||||
var strings []string
|
||||
current := ""
|
||||
for _, c := range s {
|
||||
if c == ',' {
|
||||
strings = append(strings, current)
|
||||
current = ""
|
||||
} else {
|
||||
current += string(c)
|
||||
}
|
||||
}
|
||||
if current != "" {
|
||||
strings = append(strings, current)
|
||||
}
|
||||
return strings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user