gottdad/main.go

70 lines
1.2 KiB
Go
Raw Normal View History

2020-06-14 16:27:57 +02:00
package main
import (
2021-11-06 16:33:16 +01:00
"flag"
2020-06-21 19:00:31 +02:00
"time"
2020-06-21 19:43:01 +02:00
2021-11-06 16:33:16 +01:00
_ "embed"
2021-11-06 17:13:45 +01:00
"github.com/ianschenck/envflag"
2020-06-14 16:27:57 +02:00
)
2020-06-21 19:42:41 +02:00
var (
2021-11-06 17:13:45 +01:00
cfg *Config
srv *ServerTTD
bot *Bot
configFile string
2020-06-21 19:54:01 +02:00
2021-11-06 17:13:45 +01:00
configFlag = flag.String("config", "", "config file")
2021-11-06 16:33:16 +01:00
initFlag = flag.Bool("init", false, "init config")
2021-11-06 17:13:45 +01:00
configEnv = envflag.String("CONFIG", "", "config file")
initEnv = envflag.Bool("INIT", false, "init config")
2020-06-21 19:42:41 +02:00
)
2020-06-14 16:27:57 +02:00
func main() {
2020-06-22 11:09:16 +02:00
var err error
2020-06-15 15:04:55 +02:00
2021-11-06 16:33:16 +01:00
flag.Parse()
2021-11-06 17:13:45 +01:00
if *configFlag != "" {
configFile = *configFlag
} else if *configEnv != "" {
configFile = *configEnv
} else {
configFile = "config.json"
}
2021-11-06 16:33:16 +01:00
cfg = &Config{}
2021-11-06 17:13:45 +01:00
if *initFlag || *initEnv {
logInfoWarn("Initializing configuration..")
2021-11-06 16:33:16 +01:00
err = cfg.Init()
failError(err, "Cannot init config")
2021-11-06 17:13:45 +01:00
err = cfg.Save(configFile)
2021-11-06 16:33:16 +01:00
failError(err, "Cannot save config")
} else {
2021-11-06 17:13:45 +01:00
err = cfg.Load(configFile)
2021-11-06 16:33:16 +01:00
failError(err, "Cannot open config")
2020-06-14 16:44:40 +02:00
}
2021-11-06 16:33:16 +01:00
logInfoWarn("Starting up (%s) ...", version)
2020-06-14 16:44:40 +02:00
2020-06-21 19:42:41 +02:00
// Registering bot
2021-11-06 16:33:16 +01:00
bot = &Bot{
Config: cfg.Telegram,
}
go bot.Start()
2020-06-21 19:42:41 +02:00
2021-11-06 16:33:16 +01:00
time.Sleep(1 * time.Second)
2020-06-21 19:57:58 +02:00
2021-11-06 16:33:16 +01:00
srv = &ServerTTD{
Config: cfg.Server,
Data: &ServerDataTTD{},
Status: &ServerStatusTTD{},
2020-06-21 19:57:58 +02:00
}
2021-11-06 16:33:16 +01:00
go srv.Start()
2020-06-21 19:51:38 +02:00
2020-06-14 22:39:17 +02:00
for {
2021-11-06 16:33:16 +01:00
time.Sleep(1 * time.Second)
2020-06-14 22:39:17 +02:00
}
2020-06-14 16:27:57 +02:00
}