-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand.go
More file actions
72 lines (60 loc) · 1.31 KB
/
command.go
File metadata and controls
72 lines (60 loc) · 1.31 KB
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
// SPDX-License-Identifier: BSD-2-Clause
//
// Copyright (c) Lewis Cook <lcook@FreeBSD.org>
package command
import (
"time"
"github.com/lcook/pulsar/internal/config"
)
const (
embedColorFreeBSD int = 0xEB0028
)
type Handler struct {
Settings config.Settings
Started time.Time
commands []Command
}
type Command struct {
Name string
Description string
Handler any
}
func New(settings config.Settings) *Handler {
h := &Handler{
Settings: settings,
Started: time.Now(),
}
available := map[string]Command{
"help": {"help", "Show this help page", h.Help},
"role": {"role", "Assign yourself to a defined role", h.Role},
"bug": {
"bug",
"Display information of a Bugzilla report providing an ID",
h.Bug,
},
"status": {"status", "Display bot status", h.Status},
"review": {
"review",
"Display information of a Phabricator differential revision providing an ID",
h.Review,
},
"user": {
"user",
"Display user information of a provided ID",
h.User,
},
}
for _, name := range settings.Commands {
if cmd, ok := available[name]; ok {
h.commands = append(h.commands, cmd)
}
}
return h
}
func (h *Handler) Handlers() []any {
hnd := make([]any, 0, len(h.commands))
for _, handler := range h.commands {
hnd = append(hnd, handler.Handler)
}
return hnd
}