Milen/main.go

43 lines
885 B
Go

2020-05-11 05:30:07 +07:00
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/commands"
"gitea.teamortix.com/chanbakjsd/Milen/db"
"gitea.teamortix.com/chanbakjsd/Milen/reactrole"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
func main() {
cfg := LoadConfig()
util.ReportTarget = cfg.ReportTarget
dg, err := discordgo.New("Bot " + cfg.Token)
if err != nil {
fmt.Println("error creating Discord session,", err)
return
}
dg.AddHandler(commands.Event)
dg.AddHandler(reactrole.EventAdd)
dg.AddHandler(reactrole.EventRemove)
err = dg.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
dg.Close()
db.Close()
}