Compare commits
No commits in common. "04aef2f0e44e4ee4bcdb419f6ade282f27b5ddfc" and "a151b081422ae331f02e4eb779545efef726fbe9" have entirely different histories.
04aef2f0e4
...
a151b08142
35
bot/bot.go
35
bot/bot.go
@ -76,8 +76,7 @@ func (b *Bot) RegisterHandlers() {
|
||||
}
|
||||
|
||||
func Run() error {
|
||||
initConfig()
|
||||
go reloadConfig()
|
||||
setupConfig()
|
||||
|
||||
if err := lib.SeedMathRand(); err != nil {
|
||||
log.Warn(err)
|
||||
@ -98,7 +97,8 @@ func Run() error {
|
||||
|
||||
dg.Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages
|
||||
|
||||
if err = dg.Open(); err != nil {
|
||||
err = dg.Open()
|
||||
if err != nil {
|
||||
log.Fatalf("error opening connection: %v\n", err)
|
||||
}
|
||||
|
||||
@ -115,7 +115,9 @@ func Run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
func setupConfig() {
|
||||
var err error
|
||||
|
||||
C = NewConfig()
|
||||
|
||||
viper.SetEnvPrefix("BEEPBOOP")
|
||||
@ -125,43 +127,22 @@ func initConfig() {
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
viper.SetDefault("debug", false)
|
||||
|
||||
viper.BindEnv("DEBUG")
|
||||
viper.BindEnv("DISCORD_TOKEN")
|
||||
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
||||
|
||||
loadConfig()
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
log.Fatalf("fatal error config file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.WithField("filename", viper.ConfigFileUsed()).Info(
|
||||
"loaded configuration file",
|
||||
)
|
||||
|
||||
err := viper.Unmarshal(&C)
|
||||
err = viper.Unmarshal(&C)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to decode into struct: %v", err)
|
||||
}
|
||||
|
||||
if viper.GetBool("debug") {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
} else {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
}
|
||||
|
||||
func reloadConfig() {
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGHUP)
|
||||
for {
|
||||
<-sc
|
||||
|
||||
loadConfig()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user