various improvements
This commit is contained in:
parent
d5272262da
commit
1a6953900c
14 changed files with 71 additions and 49 deletions
|
@ -2,6 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"time"
|
||||
|
@ -11,11 +12,11 @@ type config struct {
|
|||
APIToken string
|
||||
DebugMode bool
|
||||
PrivilegedUsers []int64
|
||||
Shutup map[int64]time.Time //is always filled at startup, not present in config
|
||||
Webserver struct {
|
||||
Shutup map[int64]time.Time //! is always filled at startup, not present in config
|
||||
Webserver struct {
|
||||
Port string
|
||||
}
|
||||
Balonlyl struct {
|
||||
Balonlyl struct {
|
||||
EnabledChats []int64
|
||||
BalonlylAT string
|
||||
TriggerWords []string
|
||||
|
@ -39,7 +40,7 @@ func LoadConfig() {
|
|||
|
||||
configFile, err := os.ReadFile("config.toml")
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("rror opening config file")
|
||||
log.Panic().Err(err).Msg("error opening config file")
|
||||
}
|
||||
|
||||
_, err = toml.Decode(string(configFile), &BotConfig)
|
||||
|
@ -49,6 +50,10 @@ func LoadConfig() {
|
|||
|
||||
BotConfig.Shutup = make(map[int64]time.Time)
|
||||
|
||||
if !BotConfig.DebugMode {
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
log.Info().Msg("loaded config file")
|
||||
log.Debug().Interface("config", BotConfig).Msg("")
|
||||
|
||||
|
@ -59,27 +64,27 @@ func EncodeToml() {
|
|||
exampleConfig := config{
|
||||
APIToken: "1234567:h8Y7ma7hMG93kxDx5o",
|
||||
DebugMode: false,
|
||||
PrivilegedUsers: []int64{1234567,9764382423},
|
||||
Webserver: struct{ Port string }{
|
||||
PrivilegedUsers: []int64{1234567, 9764382423},
|
||||
Webserver: struct{ Port string }{
|
||||
Port: "3000",
|
||||
},
|
||||
Balonlyl: struct {
|
||||
Balonlyl: struct {
|
||||
EnabledChats []int64
|
||||
BalonlylAT string
|
||||
TriggerWords []string
|
||||
}{
|
||||
EnabledChats: []int64{353454534,8743658},
|
||||
EnabledChats: []int64{353454534, 8743658},
|
||||
BalonlylAT: "@Balonlyl",
|
||||
TriggerWords: []string{"French, France"},
|
||||
},
|
||||
GayPoints: struct {
|
||||
GayPoints: struct {
|
||||
EnabledChats []int64
|
||||
ModifyUsers []int64
|
||||
}{
|
||||
EnabledChats: []int64{353454534,8743658},
|
||||
ModifyUsers: []int64{3827468324,1736576},
|
||||
EnabledChats: []int64{353454534, 8743658},
|
||||
ModifyUsers: []int64{3827468324, 1736576},
|
||||
},
|
||||
Download: struct {
|
||||
Download: struct {
|
||||
Prefix string
|
||||
Yourls struct {
|
||||
APIPath string
|
||||
|
@ -97,21 +102,18 @@ func EncodeToml() {
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
f, err := os.Create("config.toml.example")
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file. Cannot open config.toml.example")
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file. Cannot open config.toml.example")
|
||||
}
|
||||
|
||||
if err := toml.NewEncoder(f).Encode(exampleConfig); err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file")
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file. Cannot close config.toml.example")
|
||||
|
||||
}
|
||||
|
||||
log.Info().Msg("Wrote example config to config.toml.example. Bye Bye")
|
||||
}
|
||||
|
||||
if err := toml.NewEncoder(f).Encode(exampleConfig); err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file")
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Panic().Err(err).Msg("error encoding config file. Cannot close config.toml.example")
|
||||
|
||||
}
|
||||
|
||||
log.Info().Msg("Wrote example config to config.toml.example. Bye Bye")
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue