diff --git a/config.toml.example b/config.toml.example new file mode 100644 index 0000000..b3568b5 --- /dev/null +++ b/config.toml.example @@ -0,0 +1,21 @@ +APIToken = "1234567:h8Y7ma7hMG93kxDx5o" +DebugMode = false +PrivilegedUsers = [1234567, 9764382423] + +[Webserver] + Port = "3000" + +[Balonlyl] + EnabledChats = [353454534, 8743658] + BalonlylAT = "@Balonlyl" + TriggerWords = ["French, France"] + +[GayPoints] + EnabledChats = [353454534, 8743658] + ModifyUsers = [3827468324, 1736576] + +[Download] + Prefix = "https://bloater.example.com" + [Download.Yourls] + APIPath = "https://short.com/yourls-api.php" + Signature = "kfn83h28r" diff --git a/config/config.go b/config/config.go index 693fbf1..233c767 100644 --- a/config/config.go +++ b/config/config.go @@ -11,7 +11,10 @@ type config struct { APIToken string DebugMode bool PrivilegedUsers []int64 - Shutup map[int64]time.Time + Shutup map[int64]time.Time //is always filled at startup, not present in config + Webserver struct { + Port string + } Balonlyl struct { EnabledChats []int64 BalonlylAT string @@ -50,3 +53,65 @@ func LoadConfig() { log.Debug().Interface("config", BotConfig).Msg("") } + +func EncodeToml() { + + exampleConfig := config{ + APIToken: "1234567:h8Y7ma7hMG93kxDx5o", + DebugMode: false, + PrivilegedUsers: []int64{1234567,9764382423}, + Webserver: struct{ Port string }{ + Port: "3000", + }, + Balonlyl: struct { + EnabledChats []int64 + BalonlylAT string + TriggerWords []string + }{ + EnabledChats: []int64{353454534,8743658}, + BalonlylAT: "@Balonlyl", + TriggerWords: []string{"French, France"}, + }, + GayPoints: struct { + EnabledChats []int64 + ModifyUsers []int64 + }{ + EnabledChats: []int64{353454534,8743658}, + ModifyUsers: []int64{3827468324,1736576}, + }, + Download: struct { + Prefix string + Yourls struct { + APIPath string + Signature string + } + }{ + Prefix: "https://bloater.example.com", + Yourls: struct { + APIPath string + Signature string + }{ + APIPath: "https://short.com/yourls-api.php", + Signature: "kfn83h28r", + }, + }, + } + + + + 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 := 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") +os.Exit(0) +} \ No newline at end of file diff --git a/main.go b/main.go index 264ad7e..22789b1 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,30 @@ package main import ( + "flag" "fmt" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "os" "time" "watn3y/bloaterbotv3/commands/gaypoints" "watn3y/bloaterbotv3/commands/notify" "watn3y/bloaterbotv3/config" "watn3y/bloaterbotv3/webserver" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" ) func main() { fmt.Println("Starting bloaterbot...") - configureLogger() + + encodeConfig := flag.Bool("generate-example-config", false, "Generates a example config to config.toml.example") + flag.Parse() + if *encodeConfig { + config.EncodeToml() + os.Exit(0) + } + config.LoadConfig() gaypoints.InitDB() notify.InitDB() diff --git a/webserver/webserver.go b/webserver/webserver.go index 13bbc2e..0f62970 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -1,17 +1,19 @@ package webserver import ( - "github.com/rs/zerolog/log" "net/http" + "watn3y/bloaterbotv3/config" + + "github.com/rs/zerolog/log" ) func RunWeb() { fs := http.FileServer(http.Dir("./videos")) http.Handle("/", fs) - log.Info().Str("port", "3556").Str("path", "./videos").Msg("Starting webserver") + log.Info().Str("port", config.BotConfig.Webserver.Port).Str("path", "./videos").Msg("Starting webserver") - err := http.ListenAndServe(":3556", nil) + err := http.ListenAndServe(":" + config.BotConfig.Webserver.Port, nil) if err != nil { log.Panic().Err(err).Msg("Failed to start webserver")