Added config generator

This commit is contained in:
watn3y 2023-12-28 23:46:52 +01:00
parent dbb7552fe3
commit d4fd21d98e
4 changed files with 104 additions and 7 deletions

21
config.toml.example Normal file
View file

@ -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"

View file

@ -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)
}

15
main.go
View file

@ -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()

View file

@ -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")