Fancy usage of arrays in config files

This commit is contained in:
Tyler 2020-12-17 19:04:56 -05:00
parent ce4fcb44e0
commit 4464c878e9
1 changed files with 13 additions and 2 deletions

15
main.go
View File

@ -42,7 +42,14 @@ func main() {
log.Fatalln("Invalid token/token is not set")
}
channelStrs := strings.Split(viper.GetString("channels"), ",")
var channelStrs []string
if viper.ConfigFileUsed() != "" {
channelStrs = viper.GetStringSlice("channels")
} else {
channelStrs = strings.Split(viper.GetString("channels"), ",")
}
channels = make([]discord.ChannelID, len(channelStrs))
for i, channelStr := range channelStrs {
@ -55,7 +62,11 @@ func main() {
channels[i] = discord.ChannelID(sf)
}
prohibitedPhrases = strings.Split(viper.GetString("prohibitedPhrases"), ",")
if viper.ConfigFileUsed() != "" {
prohibitedPhrases = viper.GetStringSlice("phohibitedPhrases")
} else {
prohibitedPhrases = strings.Split(viper.GetString("prohibitedPhrases"), ",")
}
var err error