gottdad/main.go

57 lines
872 B
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"
2020-06-14 16:27:57 +02:00
)
2020-06-21 19:42:41 +02:00
var (
2021-11-06 17:25:42 +01:00
cfg *Config
srv *ServerTTD
bot *Bot
2020-06-21 19:54:01 +02:00
2021-11-06 17:25:42 +01:00
configFlag = flag.String("config", "config.json", "config file")
2021-11-06 16:33:16 +01:00
initFlag = flag.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()
cfg = &Config{}
2021-11-06 17:25:42 +01:00
if *initFlag {
2021-11-06 17:13:45 +01:00
logInfoWarn("Initializing configuration..")
2021-11-06 16:33:16 +01:00
err = cfg.Init()
failError(err, "Cannot init config")
2021-11-06 17:25:42 +01:00
err = cfg.Save(*configFlag)
2021-11-06 16:33:16 +01:00
failError(err, "Cannot save config")
} else {
2021-11-06 17:25:42 +01:00
err = cfg.Load(*configFlag)
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
}