Bind Discord and OpenWeatherMap tokens to environment variables
This commit is contained in:
parent
d790094399
commit
d75a02554d
@ -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)
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ type (
|
||||
Config struct {
|
||||
Handler HandlerConfig `mapstructure:"handler"`
|
||||
Prefix string `mapstructure:"prefix"`
|
||||
DiscordToken string `mapstructure:"discord_token"`
|
||||
OpenWeatherMapToken string `mapstructure:"open_weather_map_token"`
|
||||
}
|
||||
|
||||
HandlerConfig struct {
|
||||
|
@ -4,3 +4,4 @@ services:
|
||||
build: .
|
||||
environment:
|
||||
- BEEPBOOP_DISCORD_TOKEN
|
||||
- BEEPBOOP_OPEN_WEATHER_MAP_TOKEN
|
||||
|
Loading…
Reference in New Issue
Block a user