mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-19 14:05:03 +08:00
fix: 修复 at_sender 默认行为符合 onebot
This commit is contained in:
parent
31cfb9283e
commit
fba4819adc
44
coolq/api.go
44
coolq/api.go
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"github.com/tidwall/sjson"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
@ -805,6 +804,9 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
|
|||||||
// https://git.io/Jtz15
|
// https://git.io/Jtz15
|
||||||
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||||
postType := context.Get("post_type").Str
|
postType := context.Get("post_type").Str
|
||||||
|
anonymous := context.Get("anonymous")
|
||||||
|
isAnonymous := anonymous.Type == gjson.Null
|
||||||
|
|
||||||
switch postType {
|
switch postType {
|
||||||
case "message":
|
case "message":
|
||||||
msgType := context.Get("message_type").Str
|
msgType := context.Get("message_type").Str
|
||||||
@ -812,32 +814,40 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
if reply.Exists() {
|
if reply.Exists() {
|
||||||
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
||||||
|
|
||||||
at := false
|
at := !isAnonymous // 除匿名消息场合外默认 true
|
||||||
if operation.Get("at_sender").Exists() {
|
if operation.Get("at_sender").Exists() {
|
||||||
at = operation.Get("at_sender").Bool()
|
at = operation.Get("at_sender").Bool()
|
||||||
}
|
}
|
||||||
|
|
||||||
if at && reply.IsArray() {
|
if !isAnonymous && at && reply.IsArray() {
|
||||||
modified, err := sjson.Set(
|
// 在 reply 数组头部插入CQ码
|
||||||
reply.Raw,
|
replySegments := make([]MSG, 0)
|
||||||
"-1",
|
segments := make([]MSG, 0)
|
||||||
MSG{
|
segments = append(segments, MSG{
|
||||||
"type": "at",
|
"type": "at",
|
||||||
"data": MSG{
|
"data": MSG{
|
||||||
"qq": context.Get("sender.user_id").Int(),
|
"qq": context.Get("sender.user_id").Int(),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
})
|
||||||
|
|
||||||
|
err := json.UnmarshalFromString(reply.Raw, replySegments)
|
||||||
if err != nil {
|
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)
|
reply = gjson.Parse(modified)
|
||||||
} else if at && reply.Type == gjson.String {
|
} else if !isAnonymous && at && reply.Type == gjson.String {
|
||||||
reply = gjson.Parse(fmt.Sprintf(
|
reply = gjson.Parse(fmt.Sprintf(
|
||||||
"\"%s[CQ:at,qq=%d]\"",
|
"\"[CQ:at,qq=%d]%s\"",
|
||||||
reply.String(),
|
|
||||||
context.Get("sender.user_id").Int(),
|
context.Get("sender.user_id").Int(),
|
||||||
|
reply.String(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,8 +859,6 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msgType == "group" {
|
if msgType == "group" {
|
||||||
anonymous := context.Get("anonymous")
|
|
||||||
isAnonymous := anonymous.Type == gjson.Null
|
|
||||||
if operation.Get("delete").Bool() {
|
if operation.Get("delete").Bool() {
|
||||||
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
2262
coolq/cqcode.go
2262
coolq/cqcode.go
File diff suppressed because it is too large
Load Diff
1
go.mod
1
go.mod
@ -20,7 +20,6 @@ require (
|
|||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
||||||
github.com/tidwall/gjson v1.6.8
|
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/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||||
|
2
go.sum
2
go.sum
@ -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/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
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 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user