From 4a27a60456cb808964502390c9b88dfeabb2527e Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Mon, 4 Apr 2022 21:56:18 +0800 Subject: [PATCH] coolq: fix static check --- coolq/bot.go | 2 ++ coolq/cqcode.go | 35 +++++++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 407800f..1d6a261 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -361,6 +361,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen default: if session == nil && groupID != 0 { msg := bot.Client.SendGroupTempMessage(groupID, target, m) + //lint:ignore SA9003 if msg != nil { // nolint // todo(Mrs4s) // id = bot.InsertTempMessage(target, msg) @@ -372,6 +373,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen log.Errorf("发送临时会话消息失败: %v", err) break } + //lint:ignore SA9003 if msg != nil { // nolint // todo(Mrs4s) // id = bot.InsertTempMessage(target, msg) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index c9d3c54..96e1b92 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -142,16 +142,13 @@ func ToArrayMessage(e []message.IMessageElement, source message.Source) (r []glo "data": map[string]string{"data": o.Content}, } case *message.AtElement: - if o.Target == 0 { - m = global.MSG{ - "type": "at", - "data": map[string]string{"qq": "all"}, - } - } else { - m = global.MSG{ - "type": "at", - "data": map[string]string{"qq": strconv.FormatUint(uint64(o.Target), 10)}, - } + target := "all" + if o.Target != 0 { + target = strconv.FormatUint(uint64(o.Target), 10) + } + m = global.MSG{ + "type": "at", + "data": map[string]string{"qq": target}, } case *message.RedBagElement: m = global.MSG{ @@ -236,9 +233,7 @@ func ToArrayMessage(e []message.IMessageElement, source message.Source) (r []glo default: continue } - if m != nil { - r = append(r, m) - } + r = append(r, m) } return } @@ -315,9 +310,9 @@ func ToStringMessage(e []message.IMessageElement, source message.Source, isRaw . } arg += ",subType=" + strconv.FormatInt(int64(o.ImageBizType), 10) if ur { - write("[CQ:image,file=%s%s]", hex.EncodeToString(o.Md5)+".image", arg) + write("[CQ:image,file=%x.image%s]", o.Md5, arg) } else { - write("[CQ:image,file=%s,url=%s%s]", hex.EncodeToString(o.Md5)+".image", cqcode.EscapeValue(o.Url), arg) + write("[CQ:image,file=%x.image,url=%s%s]", o.Md5, cqcode.EscapeValue(o.Url), arg) } case *message.FriendImageElement: var arg string @@ -325,9 +320,9 @@ func ToStringMessage(e []message.IMessageElement, source message.Source, isRaw . arg = ",type=flash" } if ur { - write("[CQ:image,file=%s%s]", hex.EncodeToString(o.Md5)+".image", arg) + write("[CQ:image,file=%x.image%s]", o.Md5, arg) } else { - write("[CQ:image,file=%s,url=%s%s]", hex.EncodeToString(o.Md5)+".image", cqcode.EscapeValue(o.Url), arg) + write("[CQ:image,file=%x.image,url=%s%s]", cqcode.EscapeValue(o.Url), arg) } case *LocalImageElement: var arg string @@ -338,13 +333,13 @@ func ToStringMessage(e []message.IMessageElement, source message.Source, isRaw . if err == nil { m := md5.Sum(data) if ur { - write("[CQ:image,file=%s%s]", hex.EncodeToString(m[:])+".image", arg) + write("[CQ:image,file=%x.image%s]", m[:], arg) } else { - write("[CQ:image,file=%s,url=%s%s]", hex.EncodeToString(m[:])+".image", cqcode.EscapeValue(o.URL), arg) + write("[CQ:image,file=%x.image,url=%s%s]", m[:], cqcode.EscapeValue(o.URL), arg) } } case *message.GuildImageElement: - write("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", cqcode.EscapeValue(o.Url)) + write("[CQ:image,file=%x.image,url=%s]", o.Md5, cqcode.EscapeValue(o.Url)) case *message.DiceElement: write("[CQ:dice,value=%v]", o.Value) case *message.MarketFaceElement: