-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
39 lines (33 loc) · 910 Bytes
/
handlers.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
// *most* everything pertaining to handlers
package main
import (
"github.com/pkg/errors"
"github.com/diamondburned/arikawa/v2/gateway"
"github.com/lordrusk/dctl/handler"
)
var handlers = make(map[string]handler.Handler)
func (c *client) errorEHF(err error) { c.Printf("Handler failed: %s\n", err) }
// doesn't work
func (c *client) incMsgsHF(killCh chan struct{}, errCh chan error) {
cancel := c.AddHandler(func(m *gateway.MessageCreateEvent) {
guild, err := c.Guild(m.GuildID)
if err != nil {
errCh <- errors.Wrap(err, "Failed to get guild")
}
channel, err := c.Channel(m.ChannelID)
if err != nil {
errCh <- errors.Wrap(err, "Failed to get channel")
}
msg, err := genMessage(guild, channel, &m.Message, c, true)
if err != nil {
errCh <- errors.Wrap(err, "Failed to generate message")
}
c.Println(msg)
})
go func() {
select {
case <-killCh:
cancel()
}
}()
}