-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
executable file
·101 lines (85 loc) · 2.58 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"flag"
"os"
"github.com/andersfylling/disgord"
"github.com/meooow25/cfspy/bot"
"github.com/sirupsen/logrus"
)
const (
description = "CFSpy watches for Codeforces links and shows helpful previews.\n" +
"To learn more or invite the bot to your server, visit the " +
"[Github page](https://github.com/meooow25/cfspy)."
supportURL = "https://github.com/meooow25/cfspy/issues"
)
var token = os.Getenv("TOKEN")
var logger = logrus.New()
func init() {
logger.Formatter.(*logrus.TextFormatter).FullTimestamp = true
}
func main() {
serverCountFeature := flag.Bool("scf", false, "install the server count feature")
flag.Parse()
if token == "" {
logger.Fatal("TOKEN env var missing")
}
logger.Info("------------ CFSpy starting ------------")
defer logger.Info("------------ CFSpy stopped ------------")
b := bot.New(
bot.Info{
Config: disgord.Config{
BotToken: token,
Logger: logger,
// Ideally we would just set config.Intents, but somewhat misleadingly Disgord
// doesn't use intents for anything except to *add* DM message support. The reject
// events list can be used instead, which gets translated to intents.
// https://github.com/andersfylling/disgord/blob/5c80ec9176ee57789c5018848aa894d1175065eb/internal/gateway/eventclient.go#L37-L51
RejectEvents: disgord.AllEventsExcept(relevantEvents()...),
},
Name: "CFSpy",
Prefix: "c;",
Description: description,
SupportURL: supportURL,
},
)
installPingCfCommand(b)
installFeatureInfoCommand(b)
installPingCommand(b)
installStatusFeature(b)
installBlogAndCommentFeature(b)
installProblemFeature(b)
installSubmissionFeature(b)
installProfileFeature(b)
if *serverCountFeature {
installServerCountFeature(b)
}
b.Client.Gateway().StayConnectedUntilInterrupted()
}
func relevantEvents() []string {
// https://discord.com/developers/docs/topics/gateway#list-of-intents
return []string{
disgord.EvtReady,
disgord.EvtResumed,
// Guilds intent
disgord.EvtGuildCreate,
disgord.EvtGuildUpdate,
disgord.EvtGuildDelete,
disgord.EvtGuildRoleCreate,
disgord.EvtGuildRoleUpdate,
disgord.EvtGuildRoleDelete,
disgord.EvtChannelCreate,
disgord.EvtChannelUpdate,
disgord.EvtChannelDelete,
disgord.EvtChannelPinsUpdate,
// Guild messages intent
disgord.EvtMessageCreate,
disgord.EvtMessageUpdate,
disgord.EvtMessageDelete,
disgord.EvtMessageDeleteBulk,
// Guild message reactions intent
disgord.EvtMessageReactionAdd,
disgord.EvtMessageReactionRemove,
disgord.EvtMessageReactionRemoveAll,
disgord.EvtMessageReactionRemoveEmoji,
}
}