-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.go
84 lines (67 loc) · 1.53 KB
/
common.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
package hkbot
import (
. "github.com/CuteReimu/onebot"
"math/rand/v2"
"slices"
"strconv"
"strings"
)
func init() {
addCmdListener(&showTips{})
addCmdListener(&ping{})
addCmdListener(&roll{})
}
type showTips struct{}
func (t *showTips) Name() string {
return "查看帮助"
}
func (t *showTips) ShowTips(int64, int64) string {
return ""
}
func (t *showTips) CheckAuth(int64, int64) bool {
return true
}
func (t *showTips) Execute(msg *GroupMessage, _ string) MessageChain {
var ret []string
for _, h := range cmdMap {
if h.CheckAuth(msg.GroupId, msg.Sender.UserId) {
if tip := h.ShowTips(msg.GroupId, msg.Sender.UserId); len(tip) > 0 {
ret = append(ret, tip)
}
}
}
slices.Sort(ret)
return MessageChain{&Text{Text: "你可以使用以下功能:\n" + strings.Join(ret, "\n")}}
}
type ping struct{}
func (p *ping) Name() string {
return "ping"
}
func (p *ping) ShowTips(int64, int64) string {
return ""
}
func (p *ping) CheckAuth(int64, int64) bool {
return true
}
func (p *ping) Execute(_ *GroupMessage, content string) MessageChain {
if len(content) == 0 {
return MessageChain{&Text{Text: "pong"}}
}
return nil
}
type roll struct{}
func (r *roll) Name() string {
return "roll"
}
func (r *roll) ShowTips(int64, int64) string {
return ""
}
func (r *roll) CheckAuth(int64, int64) bool {
return true
}
func (r *roll) Execute(message *GroupMessage, content string) MessageChain {
if len(content) == 0 {
replyGroupMessage(true, message, &Text{Text: "roll: " + strconv.Itoa(rand.IntN(100))})
}
return nil
}