1
0
mirror of https://github.com/stryan/mumble-discord-bridge.git synced 2024-11-14 19:45:41 -05:00
mumble-discord-bridge/config.go

68 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
"layeh.com/gumble/gumble"
)
type BridgeConfig struct {
Config *gumble.Config
MumbleAddr string
MumbleInsecure bool
Auto bool
Command string
GID string
CID string
}
type BridgeState struct {
ActiveConn chan bool
Connected bool
MumbleUserCount int
DiscordUserCount int
AutoChan chan bool
}
func lookupEnvOrString(key string, defaultVal string) string {
if val, ok := os.LookupEnv(key); ok {
return val
}
return defaultVal
}
func lookupEnvOrInt(key string, defaultVal int) int {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.Atoi(val)
if err != nil {
log.Fatalf("LookupEnvOrInt[%s]: %v", key, err)
}
return v
}
return defaultVal
}
func lookupEnvOrBool(key string, defaultVal bool) bool {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.ParseBool(val)
if err != nil {
log.Fatalf("LookupEnvOrInt[%s]: %v", key, err)
}
return v
}
return defaultVal
}
func getConfig(fs *flag.FlagSet) []string {
cfg := make([]string, 0, 10)
fs.VisitAll(func(f *flag.Flag) {
cfg = append(cfg, fmt.Sprintf("%s:%q", f.Name, f.Value.String()))
})
return cfg
}