70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"time"
|
|
|
|
_ "embed"
|
|
|
|
"github.com/ianschenck/envflag"
|
|
)
|
|
|
|
var (
|
|
cfg *Config
|
|
srv *ServerTTD
|
|
bot *Bot
|
|
configFile string
|
|
|
|
configFlag = flag.String("config", "", "config file")
|
|
initFlag = flag.Bool("init", false, "init config")
|
|
configEnv = envflag.String("CONFIG", "", "config file")
|
|
initEnv = envflag.Bool("INIT", false, "init config")
|
|
)
|
|
|
|
func main() {
|
|
var err error
|
|
|
|
flag.Parse()
|
|
|
|
if *configFlag != "" {
|
|
configFile = *configFlag
|
|
} else if *configEnv != "" {
|
|
configFile = *configEnv
|
|
} else {
|
|
configFile = "config.json"
|
|
}
|
|
|
|
cfg = &Config{}
|
|
if *initFlag || *initEnv {
|
|
logInfoWarn("Initializing configuration..")
|
|
err = cfg.Init()
|
|
failError(err, "Cannot init config")
|
|
err = cfg.Save(configFile)
|
|
failError(err, "Cannot save config")
|
|
} else {
|
|
err = cfg.Load(configFile)
|
|
failError(err, "Cannot open config")
|
|
}
|
|
|
|
logInfoWarn("Starting up (%s) ...", version)
|
|
|
|
// Registering bot
|
|
bot = &Bot{
|
|
Config: cfg.Telegram,
|
|
}
|
|
go bot.Start()
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
srv = &ServerTTD{
|
|
Config: cfg.Server,
|
|
Data: &ServerDataTTD{},
|
|
Status: &ServerStatusTTD{},
|
|
}
|
|
go srv.Start()
|
|
|
|
for {
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
}
|