/
bot.go
51 lines (37 loc) · 883 Bytes
/
bot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Package bot contains the general workings of a Snart Bot.
package bot
import (
"time"
"github.com/go-snart/snart/db"
"github.com/go-snart/snart/route"
dg "github.com/bwmarrin/discordgo"
"github.com/superloach/minori"
)
// Log is the logger for the bot package.
var Log = minori.GetLogger("bot")
// Bot holds all the internal workings of a Snart bot.
type Bot struct {
DB *db.DB
Session *dg.Session
Router *route.Router
Gamers []Gamer
Interrupt chan Interrupt
Startup time.Time
}
// NewBot creates a Bot from a given DB connection.
func NewBot(d *db.DB) (*Bot, error) {
_f := "NewBot"
b := &Bot{}
Log.Info(_f, "making bot")
b.DB = d
s, _ := dg.New()
b.Session = s
b.Session.AddHandler(b.Route)
b.Router = route.NewRouter()
b.Gamers = []Gamer{
GamerUptime,
}
b.Interrupt = make(chan Interrupt)
Log.Info(_f, "made bot")
return b, nil
}