1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 05:55:04 +08:00

fix: 修复 at_sender 默认行为符合 onebot

This commit is contained in:
nnnewb 2021-02-13 18:05:28 +08:00
parent 31cfb9283e
commit fba4819adc
4 changed files with 1157 additions and 1152 deletions

View File

@ -8,7 +8,6 @@ import (
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"io/ioutil"
"math"
"os"
@ -805,6 +804,9 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
// https://git.io/Jtz15
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
postType := context.Get("post_type").Str
anonymous := context.Get("anonymous")
isAnonymous := anonymous.Type == gjson.Null
switch postType {
case "message":
msgType := context.Get("message_type").Str
@ -812,32 +814,40 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
if reply.Exists() {
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
at := false
at := !isAnonymous // 除匿名消息场合外默认 true
if operation.Get("at_sender").Exists() {
at = operation.Get("at_sender").Bool()
}
if at && reply.IsArray() {
modified, err := sjson.Set(
reply.Raw,
"-1",
MSG{
"type": "at",
"data": MSG{
"qq": context.Get("sender.user_id").Int(),
},
if !isAnonymous && at && reply.IsArray() {
// 在 reply 数组头部插入CQ码
replySegments := make([]MSG, 0)
segments := make([]MSG, 0)
segments = append(segments, MSG{
"type": "at",
"data": MSG{
"qq": context.Get("sender.user_id").Int(),
},
)
})
err := json.UnmarshalFromString(reply.Raw, replySegments)
if err != nil {
return Failed(-1, "处理 at_sender 字段时出现错误", err.Error())
return Failed(-1, "处理 at_sender 过程中发生错误", err.Error())
}
segments = append(segments, replySegments...)
modified, err := json.MarshalToString(segments)
if err != nil {
return Failed(-1, "处理 at_sender 过程中发生错误", err.Error())
}
reply = gjson.Parse(modified)
} else if at && reply.Type == gjson.String {
} else if !isAnonymous && at && reply.Type == gjson.String {
reply = gjson.Parse(fmt.Sprintf(
"\"%s[CQ:at,qq=%d]\"",
reply.String(),
"\"[CQ:at,qq=%d]%s\"",
context.Get("sender.user_id").Int(),
reply.String(),
))
}
@ -849,8 +859,6 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
}
}
if msgType == "group" {
anonymous := context.Get("anonymous")
isAnonymous := anonymous.Type == gjson.Null
if operation.Get("delete").Bool() {
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
}

File diff suppressed because it is too large Load Diff

1
go.mod
View File

@ -20,7 +20,6 @@ require (
github.com/syndtr/goleveldb v1.0.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tidwall/gjson v1.6.8
github.com/tidwall/sjson v1.1.5
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9

2
go.sum
View File

@ -119,8 +119,6 @@ github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=