-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
61 lines (47 loc) · 1.16 KB
/
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
52
53
54
55
56
57
58
59
60
61
// Package snart contains the general workings of a Snart Bot.
package snart
import (
"fmt"
"log"
"time"
"github.com/diamondburned/arikawa/v2/gateway"
"github.com/diamondburned/arikawa/v2/state"
"github.com/superloach/confy"
"github.com/go-snart/route"
)
// KeyToken is the Confy key used to fetch the Bot's token.
const KeyToken = "token"
// BaseIntents is the basic intents needed by a Bot.
const BaseIntents = gateway.IntentGuildMessages
// Bot holds all the workings of a Snart bot.
type Bot struct {
*route.Route
Intents gateway.Intents
Gamers []Gamer
Errs chan error
}
// New creates a Bot with the given token.
func New(c confy.Confy) (*Bot, error) {
token := ""
err := c.Get(KeyToken, &token)
if err != nil {
return nil, fmt.Errorf("load %q: %w", KeyToken, err)
}
s, err := state.New(token)
if err != nil {
return nil, fmt.Errorf("new state %q: %w", token, err)
}
log.Println("made state")
r, err := route.New(s, c)
if err != nil {
return nil, fmt.Errorf("new route: %w", err)
}
return &Bot{
Route: r,
Intents: BaseIntents,
Gamers: []Gamer{
GamerTimer(time.Now()), // uptime
},
Errs: make(chan error, 1),
}, nil
}