This repository was archived by the owner on Oct 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkookbot.go
More file actions
86 lines (74 loc) · 2.06 KB
/
kookbot.go
File metadata and controls
86 lines (74 loc) · 2.06 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"math/rand"
"regexp"
"strconv"
"time"
"github.com/lonelyevil/kook"
)
var commRules []handlerRule = []handlerRule{
{`^qqping`, func(ctxCommon *kook.EventDataGeneral, s []string, f func(string) string) {
delay := rand.Intn(500) + rand.Intn(100) + rand.Intn(50) + rand.Intn(14)
<-time.After(time.Millisecond * time.Duration(delay+2000))
f("来自 `QQ` 的回复: 字节=`256` 时间=`" + strconv.Itoa(delay) + "ms` TTL=`" + strconv.Itoa(61-rand.Intn(7)) + "`")
}},
}
func stdinHandler(ctx *kook.KmarkdownMessageContext) {
ctxCommon := ctx.Common
reply := func(words string) string {
resp, _ := sendMarkdown(stdoutChannel, words)
return resp.MsgID
}
for n := range commRules {
v := &commRules[n]
r := regexp.MustCompile(v.matcher)
matchs := r.FindStringSubmatch(ctxCommon.Content)
if len(matchs) > 0 {
go v.getter(ctxCommon, matchs, reply)
return
}
}
}
func portMarkdown(ctxCommon *kook.EventDataGeneral, s []string, f func(string) string) {
sendMarkdown(s[1], s[2])
}
var directRules []handlerRule = []handlerRule{
{`^\s*send\s*(\d+),(.*)$`, portMarkdown},
}
func directMessageHandler(ctxCommon *kook.EventDataGeneral) {
if ctxCommon.AuthorID != masterID {
sendMarkdownDirect(ctxCommon.AuthorID, "未授权的通信...访问拒绝 [-2]")
return
}
reply := func(words string) string {
resp, _ := sendMarkdownDirect(masterID, words)
return resp.MsgID
}
for n := range directRules {
v := &directRules[n]
r := regexp.MustCompile(v.matcher)
matchs := r.FindStringSubmatch(ctxCommon.Content)
if len(matchs) > 0 {
go v.getter(ctxCommon, matchs, reply)
return
}
}
}
func otherChanHandler(ctxCommon *kook.EventDataGeneral) {
if ctxCommon.Type != kook.MessageTypeKMarkdown {
return
}
reply := func(words string) string {
resp, _ := sendMarkdown(ctxCommon.TargetID, words)
return resp.MsgID
}
for n := range commRules {
v := &commRules[n]
r := regexp.MustCompile(v.matcher)
matchs := r.FindStringSubmatch(ctxCommon.Content)
if len(matchs) > 0 {
go v.getter(ctxCommon, matchs, reply)
return
}
}
}