-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
66 lines (53 loc) · 1.41 KB
/
main.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"
"fmt"
"log"
"os"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
"github.com/hhhapz/doc"
"github.com/hhhapz/doc/pkgsite"
)
const userAgent = "https://github.com/DiscordGophers/dr-docso (Discord Server for Go)"
func run() error {
cfg := config()
if cfg.Token == "" {
return fmt.Errorf("no token provided")
}
s := state.New("Bot " + cfg.Token)
searcher := doc.NewCachedSearcher(pkgsite.Parser, doc.UserAgent(userAgent), doc.WithDuplicateTypeFuncs())
b := botState{
cfg: cfg,
searcher: searcher,
state: s,
}
s.AddHandler(b.OnCommand)
s.AddHandler(b.OnMessage)
s.AddHandler(b.OnMessageEdit)
s.AddIntents(gateway.IntentGuildMessages | gateway.IntentGuildMessageReactions)
if err := s.Open(context.Background()); err != nil {
return fmt.Errorf("failed to open: %w", err)
}
defer s.Close()
log.Println("Gateway connection established.")
me, err := s.Me()
if err != nil {
return fmt.Errorf("could not get me: %w", err)
}
b.appID = discord.AppID(me.ID)
if err := loadCommands(s, me.ID); err != nil {
return fmt.Errorf("could not init commands: %w", err)
}
log.Println("Logged in as ", me.Tag())
go b.gcInteractionData()
go b.updateArticles()
select {}
}
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v", err)
os.Exit(1)
}
}