-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
106 lines (94 loc) · 3.4 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
102
103
104
105
106
package main
import (
"flag"
"github.com/disgoorg/disgo/handler"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"github.com/go-chi/chi/v5"
"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/commands"
"github.com/disgoorg/disgo-butler/components"
"github.com/disgoorg/disgo-butler/routes"
)
const version = "development"
var (
shouldSyncDBTables *bool
shouldSyncCommands *bool
)
func init() {
shouldSyncDBTables = flag.Bool("sync-db", false, "Whether to sync the database tables")
shouldSyncCommands = flag.Bool("sync-commands", false, "Whether to sync the commands")
flag.Parse()
}
func main() {
cfg, err := butler.LoadConfig()
if err != nil {
panic("failed to load config: " + err.Error())
}
logger := log.New(log.LstdFlags | log.Lshortfile)
logger.SetLevel(cfg.LogLevel)
logger.Info("starting Disgo-Butler...")
b := butler.New(logger, version, *cfg)
r := chi.NewRouter()
r.Route("/github", func(r chi.Router) {
r.Get("/", routes.HandleGithub(b))
r.Get("/login", routes.HandleLogin(b))
r.Post("/webhook", routes.HandleGithubWebhook(b))
})
b.SetupRoutes(r)
cr := handler.New()
cr.Route("/config", func(cr handler.Router) {
cr.Route("/aliases", func(cr handler.Router) {
cr.Command("/add", commands.HandleAliasesAdd(b))
cr.Command("/remove", commands.HandleAliasesRemove(b))
cr.Command("/list", commands.HandleAliasesList(b))
})
cr.Route("/releases", func(cr handler.Router) {
cr.Command("/add", commands.HandleReleasesAdd(b))
cr.Command("/remove", commands.HandleReleasesRemove(b))
cr.Command("/list", commands.HandleReleasesList(b))
})
cr.Route("/contributor-repos", func(cr handler.Router) {
cr.Command("/add", commands.HandleContributorReposAdd(b))
cr.Command("/remove", commands.HandleContributorReposRemove(b))
cr.Command("/list", commands.HandleContributorReposList(b))
})
})
cr.Route("/docs", func(cr handler.Router) {
cr.Command("/", commands.HandleDocs(b))
cr.Autocomplete("/", commands.HandleDocsAutocomplete(b))
})
cr.Component("/docs_action", components.HandleDocsAction(b))
cr.Component("/eval/rerun/{message_id}", components.HandleEvalRerunAction(b))
cr.Component("/eval/delete", components.HandleEvalDeleteAction)
cr.Command("/eval", commands.HandleEval(b))
cr.Command("/info", commands.HandleInfo(b))
cr.Command("/ping", commands.HandlePing)
cr.Route("/tag", func(cr handler.Router) {
cr.Command("/", commands.HandleTag(b))
cr.Autocomplete("/", commands.HandleTagListAutoComplete(b, false))
})
cr.Route("/tags", func(cr handler.Router) {
cr.Command("/create", commands.HandleCreateTag(b))
cr.Command("/edit", commands.HandleEditTag(b))
cr.Command("/delete", commands.HandleDeleteTag(b))
cr.Command("/info", commands.HandleTagInfo(b))
cr.Command("/list", commands.HandleListTags(b))
cr.Autocomplete("/edit", commands.HandleTagListAutoComplete(b, true))
cr.Autocomplete("/delete", commands.HandleTagListAutoComplete(b, true))
cr.Autocomplete("/info", commands.HandleTagListAutoComplete(b, false))
cr.Autocomplete("/list", commands.HandleTagListAutoComplete(b, false))
})
cr.Command("/close-ticket", commands.HandleCloseTicket(b))
b.SetupBot(cr)
b.SetupDB(*shouldSyncDBTables)
b.RegisterLinkedRoles()
if *shouldSyncCommands {
var guildIDs []snowflake.ID
if cfg.DevMode {
guildIDs = append(guildIDs, cfg.GuildID)
}
b.SyncCommands(commands.Commands, guildIDs...)
}
b.StartAndBlock()
}