57 lines
956 B
Go
57 lines
956 B
Go
package main
|
|
|
|
import (
|
|
"bot/src/controllers"
|
|
"bot/src/models"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
tele "gopkg.in/telebot.v4"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func config() models.Config {
|
|
file, err := os.Open("cfg.yml")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
// unmarshal the YAML data into a struct
|
|
var config models.Config
|
|
err = yaml.NewDecoder(file).Decode(&config)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return config
|
|
}
|
|
|
|
func main() {
|
|
cfg := config()
|
|
pref := tele.Settings{
|
|
Token: cfg.Token,
|
|
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
|
|
}
|
|
|
|
b, err := tele.NewBot(pref)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
|
|
dc := controllers.NewDB(cfg)
|
|
|
|
dickController := controllers.NewDick(dc)
|
|
duelController := controllers.NewDuel(b, dc)
|
|
|
|
b.Handle("/dick", dickController.Dick)
|
|
b.Handle("/top_dick", dickController.TopDick)
|
|
|
|
b.Handle("/duel", duelController.StartMatch)
|
|
b.Handle("/accept", duelController.AcceptMatch)
|
|
|
|
b.Start()
|
|
}
|