2020-12-29 15:14:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"layeh.com/gumble/gumble"
|
|
|
|
)
|
|
|
|
|
2021-01-08 14:38:21 -05:00
|
|
|
type bridgeMode int
|
2021-01-05 12:16:51 -05:00
|
|
|
|
|
|
|
const (
|
2021-01-08 14:38:21 -05:00
|
|
|
bridgeModeAuto bridgeMode = iota
|
|
|
|
bridgeModeManual
|
|
|
|
bridgeModeConstant
|
2021-01-05 12:16:51 -05:00
|
|
|
)
|
|
|
|
|
2021-01-08 14:38:21 -05:00
|
|
|
//BridgeConfig holds configuration information set at startup
|
|
|
|
//It should not change during runtime
|
2021-01-03 15:32:59 -05:00
|
|
|
type BridgeConfig struct {
|
2021-01-19 01:06:08 -05:00
|
|
|
MumbleConfig *gumble.Config
|
|
|
|
MumbleAddr string
|
|
|
|
MumbleInsecure bool
|
|
|
|
MumbleChannel string
|
|
|
|
MumbleDisableText bool
|
|
|
|
Command string
|
|
|
|
GID string
|
|
|
|
CID string
|
|
|
|
DiscordDisableText bool
|
2021-01-03 15:32:59 -05:00
|
|
|
}
|
|
|
|
|
2020-12-29 15:14:19 -05:00
|
|
|
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
|
|
|
|
}
|