2022-12-04 17:30:08 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2022-12-06 14:27:54 +03:00
|
|
|
"sync"
|
2022-12-06 00:57:09 +03:00
|
|
|
|
|
|
|
"nefrace.ru/doomer/config"
|
2022-12-06 02:04:05 +03:00
|
|
|
"nefrace.ru/doomer/db"
|
2022-12-04 17:30:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-12-06 14:27:54 +03:00
|
|
|
cfg := config.InitConfig()
|
2022-12-06 02:04:05 +03:00
|
|
|
db, err := db.NewDatabase()
|
2022-12-04 17:30:08 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cant open database: %v", err)
|
|
|
|
}
|
2022-12-06 00:57:09 +03:00
|
|
|
|
2022-12-04 17:30:08 +03:00
|
|
|
defer db.Close()
|
2022-12-06 00:57:09 +03:00
|
|
|
doomer := NewDoomer(db)
|
|
|
|
|
2022-12-06 14:27:54 +03:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
if cfg.Telegram.Token != "" {
|
|
|
|
wg.Add(1)
|
|
|
|
log.Println("Starting telegram bot")
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
dp := NewDispatcher(doomer)
|
|
|
|
log.Println(dp.Poll())
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
if cfg.Host != "" {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
app := InitServer(cfg.Host)
|
|
|
|
log.Fatal(app.Run())
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2022-12-04 17:30:08 +03:00
|
|
|
}
|