Bind Discord and OpenWeatherMap tokens to environment variables
This commit is contained in:
parent
d790094399
commit
d75a02554d
@ -22,8 +22,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Token string
|
|
||||||
|
|
||||||
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
|
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
|
||||||
|
|
||||||
C command.Config
|
C command.Config
|
||||||
@ -62,27 +60,23 @@ func main() {
|
|||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
err = viper.ReadInConfig()
|
err = viper.ReadInConfig()
|
||||||
|
viper.BindEnv("DISCORD_TOKEN")
|
||||||
|
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
||||||
|
|
||||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||||
log.Fatalf("fatal error config file: %v", err)
|
log.Fatalf("fatal error config file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Token, ok := viper.Get("discord_token").(string)
|
|
||||||
|
|
||||||
err = viper.Unmarshal(&C)
|
err = viper.Unmarshal(&C)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to decode into struct: %v", err)
|
log.Fatalf("unable to decode into struct: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if Token == "" {
|
if C.DiscordToken == "" {
|
||||||
log.Fatalf("Discord token is not set")
|
log.Fatalf("Discord token is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
dg, err := discordgo.New(fmt.Sprintf("Bot %s", C.DiscordToken))
|
||||||
log.Fatalf("Invalid type assertion")
|
|
||||||
}
|
|
||||||
|
|
||||||
dg, err := discordgo.New(fmt.Sprintf("Bot %s", Token))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error creating Discord session: %v\n", err)
|
log.Fatalf("error creating Discord session: %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ var (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Config struct {
|
Config struct {
|
||||||
Handler HandlerConfig `mapstructure:"handler"`
|
Handler HandlerConfig `mapstructure:"handler"`
|
||||||
Prefix string `mapstructure:"prefix"`
|
Prefix string `mapstructure:"prefix"`
|
||||||
|
DiscordToken string `mapstructure:"discord_token"`
|
||||||
|
OpenWeatherMapToken string `mapstructure:"open_weather_map_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
HandlerConfig struct {
|
HandlerConfig struct {
|
||||||
|
@ -4,3 +4,4 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
environment:
|
environment:
|
||||||
- BEEPBOOP_DISCORD_TOKEN
|
- BEEPBOOP_DISCORD_TOKEN
|
||||||
|
- BEEPBOOP_OPEN_WEATHER_MAP_TOKEN
|
||||||
|
Loading…
Reference in New Issue
Block a user