-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardParse.go
44 lines (40 loc) · 872 Bytes
/
cardParse.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
package main
import (
"NothinBot/EasyBot"
"regexp"
log "github.com/sirupsen/logrus"
"github.com/ysmood/gson"
)
var (
urlPath = [...]string{
"meta.news.jumpUrl",
"meta.detail_1.qqdocurl",
}
)
// 卡片消息解析(拒绝小程序)
func checkCardParse(ctx *EasyBot.CQMessage) {
if ctx.IsJsonMsg() {
log.Debug("isJsonMsg")
matches := ctx.Unescape().RegFindAllStringSubmatch(regexp.MustCompile(`\[CQ:json,data=(\{.*})]`))
var g gson.JSON
if len(matches) > 0 {
log.Debug("matches[0][1]: ", matches[0][1])
g = gson.NewFrom(matches[0][1])
url := ""
for _, s := range urlPath {
if !g.Get(s).Nil() {
url = g.Get(s).Str()
break
}
}
if url != "" {
ctx.SendForwardMsg(
EasyBot.NewForwardMsg(
EasyBot.NewMsgForwardNode(ctx.MessageID),
EasyBot.NewCustomForwardNodeOSR(url),
),
)
}
}
}
}