62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
//go:generate go run sedbot.example.go
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"go.etztech.xyz/sedbot/config"
|
|
"go.etztech.xyz/sedbot/database"
|
|
"go.etztech.xyz/sedbot/discord"
|
|
|
|
"go.jolheiser.com/beaver"
|
|
)
|
|
|
|
var configFlag string
|
|
|
|
func main() {
|
|
flag.StringVar(&configFlag, "config", "sedbot.toml", "Set config path")
|
|
flag.Parse()
|
|
|
|
beaver.Console.Format = beaver.FormatOptions{
|
|
TimePrefix: true,
|
|
StackPrefix: true,
|
|
StackLimit: 15,
|
|
LevelPrefix: true,
|
|
LevelColor: true,
|
|
}
|
|
|
|
cfg, err := config.Load(configFlag)
|
|
if err != nil {
|
|
beaver.Fatalf("could not load config: %v", err)
|
|
}
|
|
|
|
db, err := database.Load(cfg.DBPath)
|
|
if err != nil {
|
|
beaver.Fatalf("could not load database: %v", err)
|
|
}
|
|
|
|
bot, err := discord.Bot(cfg, db)
|
|
if err != nil {
|
|
beaver.Fatalf("could not start Discord bot: %v", err)
|
|
}
|
|
|
|
go func() {
|
|
if err := bot.Open(); err != nil {
|
|
beaver.Errorf("error running Discord bot: %v", err)
|
|
}
|
|
}()
|
|
|
|
beaver.Info("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
|
|
|
|
if err := bot.Close(); err != nil {
|
|
beaver.Errorf("error closing Discord bot: %v", err)
|
|
}
|
|
}
|