1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

style: fix issues reported by golangci-lint

This commit is contained in:
wdvxdr 2021-12-16 20:21:49 +08:00
parent 58e81648e5
commit 8b99d3147e
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
21 changed files with 115 additions and 130 deletions

View File

@ -34,7 +34,7 @@ func (w *JceWriter) WriteByte(b, tag byte) *JceWriter {
} }
func (w *JceWriter) WriteBool(b bool, tag byte) { func (w *JceWriter) WriteBool(b bool, tag byte) {
var by byte = 0 var by byte
if b { if b {
by = 1 by = 1
} }

View File

@ -14,6 +14,8 @@ type encoder struct {
func (msg DynamicProtoMessage) Encode() []byte { func (msg DynamicProtoMessage) Encode() []byte {
en := &encoder{} en := &encoder{}
//nolint:staticcheck
for id, value := range msg { for id, value := range msg {
key := id << 3 key := id << 3
switch v := value.(type) { switch v := value.(type) {

View File

@ -97,11 +97,12 @@ func (r *Reader) ReadTlvMap(tagSize int) (m TlvMap) {
return m return m
} }
var k uint16 var k uint16
if tagSize == 1 { switch tagSize {
case 1:
k = uint16(r.ReadByte()) k = uint16(r.ReadByte())
} else if tagSize == 2 { case 2:
k = r.ReadUInt16() k = r.ReadUInt16()
} else if tagSize == 4 { case 4:
k = uint16(r.ReadInt32()) k = uint16(r.ReadInt32())
} }
if k == 255 { if k == 255 {

View File

@ -29,7 +29,7 @@ func (t TEA) Encrypt(src []byte) (dst []byte) {
block := binary.BigEndian.Uint64(dst[i:]) block := binary.BigEndian.Uint64(dst[i:])
holder = block ^ iv1 holder = block ^ iv1
iv1 = t.encode(holder) iv1 = t.encode(holder)
iv1 = iv1 ^ iv2 iv1 ^= iv2
iv2 = holder iv2 = holder
binary.BigEndian.PutUint64(dst[i:], iv1) binary.BigEndian.PutUint64(dst[i:], iv1)
} }

View File

@ -3,7 +3,6 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"fmt"
"math/rand" "math/rand"
"time" "time"
@ -14,7 +13,6 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/oidb" "github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/profilecard" "github.com/Mrs4s/MiraiGo/client/pb/profilecard"
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg" "github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/internal/crypto" "github.com/Mrs4s/MiraiGo/internal/crypto"
"github.com/Mrs4s/MiraiGo/internal/packets" "github.com/Mrs4s/MiraiGo/internal/packets"
@ -1080,6 +1078,7 @@ func (c *QQClient) buildQuitGroupPacket(groupCode int64) (uint16, []byte) {
return seq, packet return seq, packet
} }
/* this function is unused
// LightAppSvc.mini_app_info.GetAppInfoById // LightAppSvc.mini_app_info.GetAppInfoById
func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) { func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()
@ -1099,6 +1098,7 @@ func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) {
packet := packets.BuildUniPacket(c.Uin, seq, "LightAppSvc.mini_app_info.GetAppInfoById", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) packet := packets.BuildUniPacket(c.Uin, seq, "LightAppSvc.mini_app_info.GetAppInfoById", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet return seq, packet
} }
*/
func (c *QQClient) buildWordSegmentationPacket(data []byte) (uint16, []byte) { func (c *QQClient) buildWordSegmentationPacket(data []byte) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()

View File

@ -95,11 +95,9 @@ type QQClient struct {
fileStorageInfo *jce.FileStoragePushFSSvcList fileStorageInfo *jce.FileStoragePushFSSvcList
// message state // message state
lastMessageSeq int32
msgSvcCache *utils.Cache msgSvcCache *utils.Cache
lastC2CMsgTime int64 lastC2CMsgTime int64
transCache *utils.Cache transCache *utils.Cache
lastLostMsg string
groupSysMsgCache *GroupSystemMessages groupSysMsgCache *GroupSystemMessages
groupMsgBuilders sync.Map groupMsgBuilders sync.Map
onlinePushCache *utils.Cache onlinePushCache *utils.Cache
@ -107,7 +105,6 @@ type QQClient struct {
groupSeq int32 groupSeq int32
friendSeq int32 friendSeq int32
heartbeatEnabled bool heartbeatEnabled bool
groupDataTransSeq int32
highwayApplyUpSeq int32 highwayApplyUpSeq int32
eventHandlers *eventHandlers eventHandlers *eventHandlers
@ -150,6 +147,13 @@ type handlerInfo struct {
params requestParams params requestParams
} }
func (h *handlerInfo) getParams() requestParams {
if h == nil {
return nil
}
return h.params
}
var decoders = map[string]func(*QQClient, *incomingPacketInfo, []byte) (interface{}, error){ var decoders = map[string]func(*QQClient, *incomingPacketInfo, []byte) (interface{}, error){
"wtlogin.login": decodeLoginResponse, "wtlogin.login": decodeLoginResponse,
"wtlogin.exchange_emp": decodeExchangeEmpResponse, "wtlogin.exchange_emp": decodeExchangeEmpResponse,
@ -174,7 +178,6 @@ var decoders = map[string]func(*QQClient, *incomingPacketInfo, []byte) (interfac
"OidbSvc.0xd79": decodeWordSegmentation, "OidbSvc.0xd79": decodeWordSegmentation,
"OidbSvc.0x990": decodeTranslateResponse, "OidbSvc.0x990": decodeTranslateResponse,
"SummaryCard.ReqSummaryCard": decodeSummaryCardResponse, "SummaryCard.ReqSummaryCard": decodeSummaryCardResponse,
"LightAppSvc.mini_app_info.GetAppInfoById": decodeAppInfoResponse,
} }
func init() { func init() {
@ -866,10 +869,6 @@ func (c *QQClient) nextQWebSeq() int64 {
return atomic.AddInt64(&c.qwebSeq, 1) return atomic.AddInt64(&c.qwebSeq, 1)
} }
func (c *QQClient) nextGroupDataTransSeq() int32 {
return atomic.AddInt32(&c.groupDataTransSeq, 2)
}
func (c *QQClient) nextHighwayApplySeq() int32 { func (c *QQClient) nextHighwayApplySeq() int32 {
return atomic.AddInt32(&c.highwayApplyUpSeq, 2) return atomic.AddInt32(&c.highwayApplyUpSeq, 2)
} }

View File

@ -20,7 +20,6 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/oidb" "github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/profilecard" "github.com/Mrs4s/MiraiGo/client/pb/profilecard"
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg" "github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/internal/proto" "github.com/Mrs4s/MiraiGo/internal/proto"
"github.com/Mrs4s/MiraiGo/utils" "github.com/Mrs4s/MiraiGo/utils"
@ -794,6 +793,7 @@ func decodeWordSegmentation(_ *QQClient, _ *incomingPacketInfo, payload []byte)
return nil, errors.New("no word received") return nil, errors.New("no word received")
} }
/* unused
// LightAppSvc.mini_app_info.GetAppInfoById // LightAppSvc.mini_app_info.GetAppInfoById
func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) { func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) {
pkg := qweb.QWebRsp{} pkg := qweb.QWebRsp{}
@ -809,6 +809,7 @@ func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (
} }
return rsp.AppInfo, nil return rsp.AppInfo, nil
} }
*/
func ignoreDecoder(_ *QQClient, _ *incomingPacketInfo, _ []byte) (interface{}, error) { func ignoreDecoder(_ *QQClient, _ *incomingPacketInfo, _ []byte) (interface{}, error) {
return nil, nil return nil, nil

View File

@ -22,8 +22,7 @@ import (
"github.com/Mrs4s/MiraiGo/utils" "github.com/Mrs4s/MiraiGo/utils"
) )
type ( type guildImageUploadResponse struct {
guildImageUploadResponse struct {
UploadKey []byte UploadKey []byte
UploadIp []uint32 UploadIp []uint32
UploadPort []uint32 UploadPort []uint32
@ -35,7 +34,6 @@ type (
ResultCode int32 ResultCode int32
IsExists bool IsExists bool
} }
)
func init() { func init() {
decoders["ImgStore.QQMeetPicUp"] = decodeGuildImageStoreResponse decoders["ImgStore.QQMeetPicUp"] = decodeGuildImageStoreResponse
@ -201,20 +199,18 @@ func (s *GuildService) pullChannelMessages(guildId, channelId, beginSeq, endSeq,
param.Version = []uint64{eventVersion} param.Version = []uint64{eventVersion}
} }
withVersionFlag := uint32(0)
if eventVersion != 0 {
withVersionFlag = 1
}
directFlag := uint32(0)
if direct {
directFlag = 1
}
payload, _ := proto.Marshal(&channel.ChannelMsgReq{ payload, _ := proto.Marshal(&channel.ChannelMsgReq{
ChannelParam: param, ChannelParam: param,
WithVersionFlag: proto.Uint32(func() uint32 { WithVersionFlag: &withVersionFlag,
if eventVersion != 0 { DirectMessageFlag: &directFlag,
return 1
}
return 0
}()),
DirectMessageFlag: proto.Uint32(func() uint32 {
if direct {
return 1
}
return 0
}()),
}) })
seq := s.c.nextSeq() seq := s.c.nextSeq()
packet := packets.BuildUniPacket(s.c.Uin, seq, "trpc.group_pro.synclogic.SyncLogic.GetChannelMsg", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload) packet := packets.BuildUniPacket(s.c.Uin, seq, "trpc.group_pro.synclogic.SyncLogic.GetChannelMsg", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload)

View File

@ -124,10 +124,9 @@ func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*Gro
/* -------- TextToSpeech -------- */ /* -------- TextToSpeech -------- */
func (c *QQClient) GetTts(text string) ([]byte, error) { func (c *QQClient) GetTts(text string) ([]byte, error) {
url := "https://textts.qq.com/cgi-bin/tts" apiUrl := "https://textts.qq.com/cgi-bin/tts"
bt, _ := json.Marshal(text) data := fmt.Sprintf(`{"appid": "201908021016","sendUin": %v,"text": %q}`, c.Uin, text)
data := fmt.Sprintf(`{"appid": "201908021016","sendUin": %v,"text": %s}`, c.Uin, bt) rsp, err := utils.HttpPostBytesWithCookie(apiUrl, []byte(data), c.getCookies())
rsp, err := utils.HttpPostBytesWithCookie(url, []byte(data), c.getCookies())
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to post to tts server") return nil, errors.Wrap(err, "failed to post to tts server")
} }

View File

@ -32,8 +32,7 @@ func init() {
var imgWaiter = utils.NewUploadWaiter() var imgWaiter = utils.NewUploadWaiter()
type ( type imageUploadResponse struct {
imageUploadResponse struct {
UploadKey []byte UploadKey []byte
UploadIp []uint32 UploadIp []uint32
UploadPort []uint32 UploadPort []uint32
@ -45,14 +44,13 @@ type (
ResultCode int32 ResultCode int32
IsExists bool IsExists bool
} }
)
func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*message.GroupImageElement, error) { func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*message.GroupImageElement, error) {
_, _ = img.Seek(0, io.SeekStart) // safe _, _ = img.Seek(0, io.SeekStart) // safe
fh, length := utils.ComputeMd5AndLength(img) fh, length := utils.ComputeMd5AndLength(img)
_, _ = img.Seek(0, io.SeekStart) _, _ = img.Seek(0, io.SeekStart)
key := hex.EncodeToString(fh) key := string(fh)
imgWaiter.Wait(key) imgWaiter.Wait(key)
defer imgWaiter.Done(key) defer imgWaiter.Done(key)

View File

@ -95,12 +95,13 @@ func decodeMultiApplyDownResponse(_ *QQClient, _ *incomingPacketInfo, payload []
return nil, errors.New("not found") return nil, errors.New("not found")
} }
rsp := body.MultimsgApplydownRsp[0] rsp := body.MultimsgApplydownRsp[0]
prefix := func() string {
var prefix string
if rsp.MsgExternInfo != nil && rsp.MsgExternInfo.ChannelType == 2 { if rsp.MsgExternInfo != nil && rsp.MsgExternInfo.ChannelType == 2 {
return "https://ssl.htdata.qq.com" prefix = "https://ssl.htdata.qq.com"
} else {
prefix = fmt.Sprintf("http://%s:%d", binary.UInt32ToIPV4Address(uint32(rsp.Uint32DownIp[0])), body.MultimsgApplydownRsp[0].Uint32DownPort[0])
} }
return fmt.Sprintf("http://%s:%d", binary.UInt32ToIPV4Address(uint32(rsp.Uint32DownIp[0])), body.MultimsgApplydownRsp[0].Uint32DownPort[0])
}()
b, err := utils.HttpGetBytes(fmt.Sprintf("%s%s", prefix, string(rsp.ThumbDownPara)), "") b, err := utils.HttpGetBytes(fmt.Sprintf("%s%s", prefix, string(rsp.ThumbDownPara)), "")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to download by multi apply down") return nil, errors.Wrap(err, "failed to download by multi apply down")

View File

@ -75,7 +75,7 @@ func (c *QQClient) ConnectionQualityTest() *ConnectionQualityInfo {
}() }()
start := time.Now() start := time.Now()
if _, err := utils.HttpGetBytes("https://ssl.htdata.qq.com", ""); err == nil { if _, err := utils.HttpGetBytes("https://ssl.htdata.qq.com", ""); err == nil {
r.LongMessageServerResponseLatency = time.Now().Sub(start).Milliseconds() r.LongMessageServerResponseLatency = time.Since(start).Milliseconds()
} else { } else {
c.Error("test long message server response latency error: %v", err) c.Error("test long message server response latency error: %v", err)
r.LongMessageServerResponseLatency = 9999 r.LongMessageServerResponseLatency = 9999
@ -335,12 +335,7 @@ func (c *QQClient) netLoop() {
decoded, err = decoder(c, &incomingPacketInfo{ decoded, err = decoder(c, &incomingPacketInfo{
SequenceId: pkt.SequenceId, SequenceId: pkt.SequenceId,
CommandName: pkt.CommandName, CommandName: pkt.CommandName,
Params: func() requestParams { Params: info.getParams(),
if !ok {
return nil
}
return info.params
}(),
}, pkt.Payload) }, pkt.Payload)
if err != nil { if err != nil {
c.Debug("decode pkt %v error: %+v", pkt.CommandName, err) c.Debug("decode pkt %v error: %+v", pkt.CommandName, err)

View File

@ -131,6 +131,7 @@ func (s *TempSessionInfo) SendMessage(m *message.SendingMessage) (*message.TempM
} }
} }
/* this function is unused
func (c *QQClient) buildGetOneDayRoamMsgRequest(target, lastMsgTime, random int64, count uint32) (uint16, []byte) { func (c *QQClient) buildGetOneDayRoamMsgRequest(target, lastMsgTime, random int64, count uint32) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()
req := &msg.PbGetOneDayRoamMsgReq{ req := &msg.PbGetOneDayRoamMsgReq{
@ -143,6 +144,7 @@ func (c *QQClient) buildGetOneDayRoamMsgRequest(target, lastMsgTime, random int6
packet := packets.BuildUniPacket(c.Uin, seq, "MessageSvc.PbGetOneDayRoamMsg", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) packet := packets.BuildUniPacket(c.Uin, seq, "MessageSvc.PbGetOneDayRoamMsg", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet return seq, packet
} }
*/
// MessageSvc.PbSendMsg // MessageSvc.PbSendMsg
func (c *QQClient) buildFriendSendingPacket(target int64, msgSeq, r, pkgNum, pkgIndex, pkgDiv int32, time int64, m []message.IMessageElement) (uint16, []byte) { func (c *QQClient) buildFriendSendingPacket(target int64, msgSeq, r, pkgNum, pkgIndex, pkgDiv int32, time int64, m []message.IMessageElement) (uint16, []byte) {

View File

@ -35,7 +35,7 @@ func (c *QQClient) UploadGroupPtt(groupCode int64, voice io.ReadSeeker) (*messag
pttWaiter.Wait(key) pttWaiter.Wait(key)
defer pttWaiter.Done(key) defer pttWaiter.Done(key)
ext := c.buildGroupPttStoreBDHExt(groupCode, fh[:], int32(length), 0, int32(length)) ext := c.buildGroupPttStoreBDHExt(groupCode, fh, int32(length), 0, int32(length))
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{ rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
CommandID: 29, CommandID: 29,
Body: voice, Body: voice,
@ -60,8 +60,8 @@ func (c *QQClient) UploadGroupPtt(groupCode int64, voice io.ReadSeeker) (*messag
Ptt: &msg.Ptt{ Ptt: &msg.Ptt{
FileType: proto.Int32(4), FileType: proto.Int32(4),
SrcUin: &c.Uin, SrcUin: &c.Uin,
FileMd5: fh[:], FileMd5: fh,
FileName: proto.String(hex.EncodeToString(fh[:]) + ".amr"), FileName: proto.String(hex.EncodeToString(fh) + ".amr"),
FileSize: proto.Int32(int32(length)), FileSize: proto.Int32(int32(length)),
GroupFileKey: pkt.TryupPttRsp[0].FileKey, GroupFileKey: pkt.TryupPttRsp[0].FileKey,
BoolValid: proto.Bool(true), BoolValid: proto.Bool(true),
@ -81,7 +81,7 @@ func (c *QQClient) UploadPrivatePtt(target int64, voice io.ReadSeeker) (*message
pttWaiter.Wait(key) pttWaiter.Wait(key)
defer pttWaiter.Done(key) defer pttWaiter.Done(key)
ext := c.buildC2CPttStoreBDHExt(target, fh[:], int32(length), int32(length)) ext := c.buildC2CPttStoreBDHExt(target, fh, int32(length), int32(length))
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{ rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
CommandID: 26, CommandID: 26,
Body: voice, Body: voice,
@ -107,8 +107,8 @@ func (c *QQClient) UploadPrivatePtt(target int64, voice io.ReadSeeker) (*message
FileType: proto.Int32(4), FileType: proto.Int32(4),
SrcUin: &c.Uin, SrcUin: &c.Uin,
FileUuid: pkt.ApplyUploadRsp.Uuid, FileUuid: pkt.ApplyUploadRsp.Uuid,
FileMd5: fh[:], FileMd5: fh,
FileName: proto.String(hex.EncodeToString(fh[:]) + ".amr"), FileName: proto.String(hex.EncodeToString(fh) + ".amr"),
FileSize: proto.Int32(int32(length)), FileSize: proto.Int32(int32(length)),
// Reserve: constructPTTExtraInfo(1, int32(len(voice))), // todo length // Reserve: constructPTTExtraInfo(1, int32(len(voice))), // todo length
BoolValid: proto.Bool(true), BoolValid: proto.Bool(true),

View File

@ -101,15 +101,14 @@ func (c *QQClient) SendGuildMusicShare(guildID, channelID uint64, msg *message.M
func (c *QQClient) buildRichMsgSendingPacket(guild uint64, target int64, msg *message.MusicShareElement, sendType uint32) (uint16, []byte) { func (c *QQClient) buildRichMsgSendingPacket(guild uint64, target int64, msg *message.MusicShareElement, sendType uint32) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()
tp := musicType[msg.MusicType] // MusicType tp := musicType[msg.MusicType] // MusicType
msgStyle := uint32(0)
if msg.MusicUrl != "" {
msgStyle = 4
}
body := &oidb.DB77ReqBody{ body := &oidb.DB77ReqBody{
AppId: tp.appID, AppId: tp.appID,
AppType: tp.appType, AppType: tp.appType,
MsgStyle: func() uint32 { MsgStyle: msgStyle,
if msg.MusicUrl == "" {
return 0
}
return 4
}(),
ClientInfo: &oidb.DB77ClientInfo{ ClientInfo: &oidb.DB77ClientInfo{
Platform: tp.platform, Platform: tp.platform,
SdkVersion: tp.sdkVersion, SdkVersion: tp.sdkVersion,

View File

@ -138,31 +138,26 @@ func (c *QQClient) buildSystemMsgNewGroupPacket(suspicious bool) (uint16, []byte
// ProfileService.Pb.ReqSystemMsgAction.Group // ProfileService.Pb.ReqSystemMsgAction.Group
func (c *QQClient) buildSystemMsgGroupActionPacket(reqID, requester, group int64, msgType int32, isInvite, accept, block bool, reason string) (uint16, []byte) { func (c *QQClient) buildSystemMsgGroupActionPacket(reqID, requester, group int64, msgType int32, isInvite, accept, block bool, reason string) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()
subSrcId := int32(31)
groupMsgType := int32(1)
if isInvite {
subSrcId = 10016
groupMsgType = 2
}
infoType := int32(12)
if accept {
infoType = 11
}
req := &structmsg.ReqSystemMsgAction{ req := &structmsg.ReqSystemMsgAction{
MsgType: msgType, MsgType: msgType,
MsgSeq: reqID, MsgSeq: reqID,
ReqUin: requester, ReqUin: requester,
SubType: 1, SubType: 1,
SrcId: 3, SrcId: 3,
SubSrcId: func() int32 { SubSrcId: subSrcId,
if isInvite { GroupMsgType: groupMsgType,
return 10016
}
return 31
}(),
GroupMsgType: func() int32 {
if isInvite {
return 2
}
return 1
}(),
ActionInfo: &structmsg.SystemMsgActionInfo{ ActionInfo: &structmsg.SystemMsgActionInfo{
Type: func() int32 { Type: infoType,
if accept {
return 11
}
return 12
}(),
GroupCode: group, GroupCode: group,
Blacklist: block, Blacklist: block,
Msg: reason, Msg: reason,
@ -178,6 +173,10 @@ func (c *QQClient) buildSystemMsgGroupActionPacket(reqID, requester, group int64
// ProfileService.Pb.ReqSystemMsgAction.Friend // ProfileService.Pb.ReqSystemMsgAction.Friend
func (c *QQClient) buildSystemMsgFriendActionPacket(reqID, requester int64, accept bool) (uint16, []byte) { func (c *QQClient) buildSystemMsgFriendActionPacket(reqID, requester int64, accept bool) (uint16, []byte) {
seq := c.nextSeq() seq := c.nextSeq()
infoType := int32(3)
if accept {
infoType = 2
}
req := &structmsg.ReqSystemMsgAction{ req := &structmsg.ReqSystemMsgAction{
MsgType: 1, MsgType: 1,
MsgSeq: reqID, MsgSeq: reqID,
@ -186,12 +185,7 @@ func (c *QQClient) buildSystemMsgFriendActionPacket(reqID, requester int64, acce
SrcId: 6, SrcId: 6,
SubSrcId: 7, SubSrcId: 7,
ActionInfo: &structmsg.SystemMsgActionInfo{ ActionInfo: &structmsg.SystemMsgActionInfo{
Type: func() int32 { Type: infoType,
if accept {
return 2
}
return 3
}(),
Blacklist: false, Blacklist: false,
AddFrdSNInfo: &structmsg.AddFrdSNInfo{}, AddFrdSNInfo: &structmsg.AddFrdSNInfo{},
}, },

View File

@ -200,12 +200,12 @@ func NewUrlShare(url, title, content, image string) *ServiceElement {
} }
} }
func NewRichXml(template string, ResId int64) *ServiceElement { func NewRichXml(template string, resID int64) *ServiceElement {
if ResId == 0 { if resID == 0 {
ResId = 60 // 默认值60 resID = 60 // 默认值60
} }
return &ServiceElement{ return &ServiceElement{
Id: int32(ResId), Id: int32(resID),
Content: template, Content: template,
SubType: "xml", SubType: "xml",
} }

View File

@ -138,8 +138,7 @@ func (e *GroupImageElement) Pack() (r []*msg.Elem) {
return []*msg.Elem{elem} return []*msg.Elem{elem}
} }
func (e *FriendImageElement) Pack() (r []*msg.Elem) { func (e *FriendImageElement) Pack() []*msg.Elem {
r = []*msg.Elem{}
image := &msg.NotOnlineImage{ image := &msg.NotOnlineImage{
FilePath: &e.ImageId, FilePath: &e.ImageId,
ResId: &e.ImageId, ResId: &e.ImageId,

View File

@ -423,12 +423,10 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
if isOk := strings.Contains(content, "<?xml"); isOk { if isOk := strings.Contains(content, "<?xml"); isOk {
res = append(res, NewRichXml(content, int64(elem.RichMsg.GetServiceId()))) res = append(res, NewRichXml(content, int64(elem.RichMsg.GetServiceId())))
continue continue
} else { } else if json.Valid(utils.S2B(content)) {
if json.Valid(utils.S2B(content)) {
res = append(res, NewRichJson(content)) res = append(res, NewRichJson(content))
continue continue
} }
}
res = append(res, NewText(content)) res = append(res, NewText(content))
} }
} }

View File

@ -68,6 +68,6 @@ func SendICMPRequest(addr *net.IPAddr, seq int) (int64, error) {
if err != nil { if err != nil {
return 0, errors.Wrap(err, "read icmp conn error") return 0, errors.Wrap(err, "read icmp conn error")
} }
duration := time.Now().Sub(start).Milliseconds() duration := time.Since(start).Milliseconds()
return duration, nil return duration, nil
} }

View File

@ -15,6 +15,7 @@ func RandomString(len int) string {
func RandomStringRange(length int, str string) string { func RandomStringRange(length int, str string) string {
sb := strings.Builder{} sb := strings.Builder{}
sb.Grow(length)
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
sb.WriteByte(str[rand.Intn(len(str))]) sb.WriteByte(str[rand.Intn(len(str))])
} }