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"
|
2020-05-30 12:48:22 +07:00
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/level"
|
2020-06-06 09:25:21 +07:00
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/persistent"
|
2020-05-11 05:30:07 +07:00
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/reactrole"
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cfg := LoadConfig()
|
2020-05-30 12:51:04 +07:00
|
|
|
commands.CommonReplacement = cfg.MacroReplace
|
|
|
|
commands.Macro = cfg.Macro
|
2020-05-30 14:50:26 +07:00
|
|
|
level.Roles = cfg.LevelRoles
|
2020-05-11 05:30:07 +07:00
|
|
|
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)
|
2020-05-30 12:48:22 +07:00
|
|
|
dg.AddHandler(level.Event)
|
2020-05-11 05:30:07 +07:00
|
|
|
dg.AddHandler(reactrole.EventAdd)
|
|
|
|
dg.AddHandler(reactrole.EventRemove)
|
|
|
|
|
2020-05-30 14:50:26 +07:00
|
|
|
go level.QueueRoles(dg)
|
2020-06-06 09:25:21 +07:00
|
|
|
go persistent.SaveLoop(dg)
|
2020-05-30 14:50:26 +07:00
|
|
|
|
2020-05-11 05:30:07 +07:00
|
|
|
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)
|
2020-05-31 03:23:23 +07:00
|
|
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
2020-05-11 05:30:07 +07:00
|
|
|
<-sc
|
2020-06-06 09:25:21 +07:00
|
|
|
persistent.Save(dg)
|
2020-05-31 03:23:23 +07:00
|
|
|
err = dg.Close()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("error closing connection,", err)
|
|
|
|
}
|
2020-05-11 05:30:07 +07:00
|
|
|
db.Close()
|
|
|
|
}
|