Added config generator
This commit is contained in:
parent
dbb7552fe3
commit
d4fd21d98e
4 changed files with 104 additions and 7 deletions
21
config.toml.example
Normal file
21
config.toml.example
Normal 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"
|
|
@ -11,7 +11,10 @@ type config struct {
|
||||||
APIToken string
|
APIToken string
|
||||||
DebugMode bool
|
DebugMode bool
|
||||||
PrivilegedUsers []int64
|
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 {
|
Balonlyl struct {
|
||||||
EnabledChats []int64
|
EnabledChats []int64
|
||||||
BalonlylAT string
|
BalonlylAT string
|
||||||
|
@ -50,3 +53,65 @@ func LoadConfig() {
|
||||||
log.Debug().Interface("config", BotConfig).Msg("")
|
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
15
main.go
|
@ -1,21 +1,30 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
"watn3y/bloaterbotv3/commands/gaypoints"
|
"watn3y/bloaterbotv3/commands/gaypoints"
|
||||||
"watn3y/bloaterbotv3/commands/notify"
|
"watn3y/bloaterbotv3/commands/notify"
|
||||||
"watn3y/bloaterbotv3/config"
|
"watn3y/bloaterbotv3/config"
|
||||||
"watn3y/bloaterbotv3/webserver"
|
"watn3y/bloaterbotv3/webserver"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Starting bloaterbot...")
|
fmt.Println("Starting bloaterbot...")
|
||||||
|
|
||||||
configureLogger()
|
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()
|
config.LoadConfig()
|
||||||
gaypoints.InitDB()
|
gaypoints.InitDB()
|
||||||
notify.InitDB()
|
notify.InitDB()
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package webserver
|
package webserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"watn3y/bloaterbotv3/config"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunWeb() {
|
func RunWeb() {
|
||||||
fs := http.FileServer(http.Dir("./videos"))
|
fs := http.FileServer(http.Dir("./videos"))
|
||||||
http.Handle("/", fs)
|
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 {
|
if err != nil {
|
||||||
log.Panic().Err(err).Msg("Failed to start webserver")
|
log.Panic().Err(err).Msg("Failed to start webserver")
|
||||||
|
|
Loading…
Reference in a new issue