-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.go
66 lines (52 loc) · 1.33 KB
/
discord.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
62
63
64
65
66
package main
import (
"context"
"log"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/session"
)
type DiscordMessage *gateway.MessageCreateEvent
const clydeID = 1081004946872352958
var (
Session *session.Session
ClydeChannel discord.ChannelID
CurrentUserID string
)
var Ready chan bool = make(chan bool)
func RunDiscordSession(token string) {
Session = session.New(token)
Session.AddHandler(func(c *gateway.MessageCreateEvent) {
if c.Author.ID != clydeID || c.ChannelID != ClydeChannel {
return
}
if mode == TUI {
tui.Send(DiscordMessage(c))
} else if mode == CLI {
CLIChan <- c.Content
}
})
if err := Session.Open(context.Background()); err != nil {
if mode == TUI {
tui.Send(logMsg{Msg: "Unable to establish discord connection", Type: Error})
} else if mode == CLI {
log.Fatalln("Unable to establish discord connection")
}
}
defer Session.Close()
u, err := Session.Me()
if err != nil {
if mode == TUI {
tui.Send(logMsg{Msg: "Unable to get user", Type: Error})
} else if mode == CLI {
log.Fatalln("Unable to get user")
}
}
CurrentUserID = u.ID.String()
if mode == TUI {
tui.Send(logMsg{Msg: "Logged in as " + u.Username, Type: Info})
} else if mode == CLI {
Ready <- true
}
select {}
}