diff --git a/cmd/bb/main.go b/cmd/bb/main.go index e600f72..558923a 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -22,8 +22,6 @@ import ( ) var ( - Token string - defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"} C command.Config @@ -62,27 +60,23 @@ func main() { viper.SetConfigType("toml") viper.AddConfigPath(".") err = viper.ReadInConfig() + viper.BindEnv("DISCORD_TOKEN") + viper.BindEnv("OPEN_WEATHER_MAP_TOKEN") if _, ok := err.(viper.ConfigFileNotFoundError); !ok { log.Fatalf("fatal error config file: %v", err) } - Token, ok := viper.Get("discord_token").(string) - err = viper.Unmarshal(&C) if err != nil { log.Fatalf("unable to decode into struct: %v", err) } - if Token == "" { + if C.DiscordToken == "" { log.Fatalf("Discord token is not set") } - if !ok { - log.Fatalf("Invalid type assertion") - } - - dg, err := discordgo.New(fmt.Sprintf("Bot %s", Token)) + dg, err := discordgo.New(fmt.Sprintf("Bot %s", C.DiscordToken)) if err != nil { log.Fatalf("error creating Discord session: %v\n", err) } diff --git a/command/config.go b/command/config.go index f2ef0f5..55105f4 100644 --- a/command/config.go +++ b/command/config.go @@ -10,8 +10,10 @@ var ( type ( Config struct { - Handler HandlerConfig `mapstructure:"handler"` - Prefix string `mapstructure:"prefix"` + Handler HandlerConfig `mapstructure:"handler"` + Prefix string `mapstructure:"prefix"` + DiscordToken string `mapstructure:"discord_token"` + OpenWeatherMapToken string `mapstructure:"open_weather_map_token"` } HandlerConfig struct { diff --git a/docker-compose.yaml b/docker-compose.yaml index 9d004eb..6b8beec 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,3 +4,4 @@ services: build: . environment: - BEEPBOOP_DISCORD_TOKEN + - BEEPBOOP_OPEN_WEATHER_MAP_TOKEN