From 1ff9de190d494647c35c696c8231df1f07699bb7 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Wed, 17 Feb 2021 16:04:28 +0800 Subject: [PATCH] fix cqcode --- coolq/bot.go | 7 ++----- coolq/cqcode.go | 22 +++++++++++++++++----- global/filter.go | 4 ++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 6930e40..da884ab 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -13,17 +13,14 @@ import ( "sync" "time" - "github.com/Mrs4s/MiraiGo/utils" - - "github.com/syndtr/goleveldb/leveldb" - "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/MiraiGo/utils" "github.com/Mrs4s/go-cqhttp/global" - jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" + "github.com/syndtr/goleveldb/leveldb" ) var json = jsoniter.ConfigCompatibleWithStandardLibrary diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 2a02a51..da69761 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -361,11 +361,11 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM saveTempText := func() { if len(tempText) != 0 { if SplitURL { - for _, t := range global.SplitURL(CQCodeUnescapeValue(string(tempText))) { + for _, t := range global.SplitURL(CQCodeUnescapeText(string(tempText))) { r = append(r, message.NewText(t)) } } else { - r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText)))) + r = append(r, message.NewText(CQCodeUnescapeText(string(tempText)))) } } tempText = []rune{} @@ -783,11 +783,11 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte i, _ := strconv.ParseInt(resID, 10, 64) if i == 0 { // 默认情况下走小程序通道 - msg := message.NewLightApp(CQCodeUnescapeValue(d["data"])) + msg := message.NewLightApp(d["data"]) return msg, nil } // resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO - msg := message.NewRichJson(CQCodeUnescapeValue(d["data"])) + msg := message.NewRichJson(d["data"]) return msg, nil case "cardimage": source := d["source"] @@ -894,6 +894,12 @@ func CQCodeEscapeText(raw string) string { , -> , +& -> & + +[ -> [ + +] -> ] + */ func CQCodeEscapeValue(value string) string { ret := CQCodeEscapeText(value) @@ -920,7 +926,13 @@ func CQCodeUnescapeText(content string) string { /*CQCodeUnescapeValue 将字符串content中部分字符反转义 -, -> , +, -> , + +& -> & + +[ -> [ + +] -> ] */ func CQCodeUnescapeValue(content string) string { diff --git a/global/filter.go b/global/filter.go index 80e641a..cdbea5d 100644 --- a/global/filter.go +++ b/global/filter.go @@ -109,9 +109,9 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator { } // Eval 对payload执行And过滤 -func (andOperator *AndOperator) Eval(payload MSG) bool { +func (op *AndOperator) Eval(payload MSG) bool { res := true - for _, operand := range andOperator.operands { + for _, operand := range op.operands { if len(operand.key) == 0 { // is an operator