-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrule.go
80 lines (73 loc) · 1.5 KB
/
rule.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
// Package leafbot
// @Description:
package leafbot
import "strconv"
// Rule
/*
rule类型
*/
type Rule func(ctx *Context) bool
// MustReply
/**
* @Description:
* @param event
* @param api
* @param state
* @return bool
* example
*/
func MustReply(ctx *Context) bool {
for _, segment := range ctx.Event.Message {
if segment.Type == "reply" {
ctx.State.Data["reply_id"] = segment.Data["id"]
id, err := strconv.Atoi(segment.Data["id"])
if err != nil {
return false
}
ctx.State.Data["reply_msg"] = ctx.GetMsg(int32(id))
return true
}
}
return false
}
// OnlyToMe
/**
* @Description: 添加了该rule的插件需要在群里艾特或者私聊才会进行响应
* @param event leafBot event
* @param bot bot实例对象
* @return bool 返回是否验证通过该rule
* example
*/
func OnlyToMe(ctx *Context) bool {
if b, ok := ctx.State.Data["only_tome"]; ok {
return b.(bool)
}
return false
}
// OnlySuperUser
/**
* @Description: 加了该rule的插件只会对配置文件中配置的管理员用户进行响应
* @param event leafBot event
* @param bot bot实例对象
* @return bool 是否通过该rule验证
* example
*/
func OnlySuperUser(ctx *Context) bool {
for _, user := range GetConfig().SuperUser {
if ctx.Event.UserId == user {
return true
}
}
return false
}
// OnlyGroupMessage
/**
* @Description:
* @param event
* @param _
* @return bool
* example
*/
func OnlyGroupMessage(ctx *Context) bool {
return ctx.Event.MessageType == "group"
}