68 lines
976 B
Go
68 lines
976 B
Go
package main
|
|
|
|
import (
|
|
"dorisbot/models"
|
|
"dorisbot/pkg/config"
|
|
"dorisbot/pkg/options"
|
|
"dorisbot/pkg/svc/discord"
|
|
"dorisbot/route/routes"
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
func init() {
|
|
options.RegOptions()
|
|
}
|
|
|
|
func main() {
|
|
var err error
|
|
opts := options.GetOptions()
|
|
if opts.Help {
|
|
opts.ShowUsage()
|
|
return
|
|
}
|
|
|
|
println("Bot Svc")
|
|
cc := make(chan bool)
|
|
|
|
err = config.LoadConfig(opts.Config)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
conf := config.GetConfig()
|
|
|
|
_, err = models.NewDB(conf.Database)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
err = models.Ping()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
client, err := discord.NewClient(conf.Discord.BotToken)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = client.Connect()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer client.Close()
|
|
|
|
// setup web server
|
|
engine := routes.NewEngine()
|
|
routes.SetRoutes(engine)
|
|
go func() {
|
|
err := engine.Run(fmt.Sprintf(":%d", conf.Port))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
cc <- true
|
|
}
|
|
}()
|
|
|
|
<-cc
|
|
}
|