From d1da08a376d427a93483c5cc3b938a547726254f Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Tue, 18 Aug 2020 13:22:11 +0800 Subject: [PATCH] fix at. --- coolq/api.go | 27 +++++++++++++++------------ global/param.go | 12 ++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 9ada387..33d9dab 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -98,9 +98,23 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64, noCache bool) MSG // https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG { var str string + fixAt := func(elem []message.IMessageElement) { + for _, e := range elem { + if at, ok := e.(*message.AtElement); ok && at.Target != 0 { + at.Display = "@" + func() string { + mem := bot.Client.FindGroup(groupId).FindMember(at.Target) + if mem != nil { + return mem.DisplayName() + } + return strconv.FormatInt(at.Target, 10) + }() + } + } + } if m, ok := i.(gjson.Result); ok { if m.Type == gjson.JSON { elem := bot.ConvertObjectMessage(m, true) + fixAt(elem) mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem}) if mid == -1 { return Failed(100) @@ -125,18 +139,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo } else { elem = bot.ConvertStringMessage(str, true) } - // fix at display - for _, e := range elem { - if at, ok := e.(*message.AtElement); ok && at.Target != 0 { - at.Display = "@" + func() string { - mem := bot.Client.FindGroup(groupId).FindMember(at.Target) - if mem != nil { - return mem.DisplayName() - } - return strconv.FormatInt(at.Target, 10) - }() - } - } + fixAt(elem) mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem}) if mid == -1 { return Failed(100) diff --git a/global/param.go b/global/param.go index 259d4af..25e138f 100644 --- a/global/param.go +++ b/global/param.go @@ -6,15 +6,15 @@ import ( ) var trueSet = map[string]struct{}{ - "true": struct{}{}, - "yes": struct{}{}, - "1": struct{}{}, + "true": {}, + "yes": {}, + "1": {}, } var falseSet = map[string]struct{}{ - "false": struct{}{}, - "no": struct{}{}, - "0": struct{}{}, + "false": {}, + "no": {}, + "0": {}, } func EnsureBool(p interface{}, defaultVal bool) bool {