1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-03 18:47:41 +08:00

all: fix some issue reported by golangci-lint

This commit is contained in:
wdvxdr 2023-02-13 15:33:55 +08:00
parent 2156430a24
commit 993ec128a0
22 changed files with 71 additions and 103 deletions

View File

@ -21,10 +21,10 @@ func NewJceReader(data []byte) *JceReader {
return &JceReader{buf: data}
}
func (r *JceReader) readHead() (hd HeadData, l int) {
hd, l = r.peakHead()
func (r *JceReader) readHead() HeadData {
hd, l := r.peakHead()
r.off += l
return
return hd
}
func (r *JceReader) peakHead() (hd HeadData, l int) {
@ -86,7 +86,7 @@ func (r *JceReader) skipField(t byte) {
}
func (r *JceReader) skipNextField() {
hd, _ := r.readHead()
hd := r.readHead()
r.skipField(hd.Type)
}
@ -151,10 +151,10 @@ func (r *JceReader) skipToTag(tag int) bool {
}
func (r *JceReader) skipToStructEnd() {
hd, _ := r.readHead()
hd := r.readHead()
for hd.Type != 11 {
r.skipField(hd.Type)
hd, _ = r.readHead()
hd = r.readHead()
}
}
@ -162,7 +162,7 @@ func (r *JceReader) ReadByte(tag int) byte {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -181,7 +181,7 @@ func (r *JceReader) ReadInt16(tag int) int16 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -198,7 +198,7 @@ func (r *JceReader) ReadInt32(tag int) int32 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -217,7 +217,7 @@ func (r *JceReader) ReadInt64(tag int) int64 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -238,7 +238,7 @@ func (r *JceReader) ReadFloat32(tag int) float32 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -253,7 +253,7 @@ func (r *JceReader) ReadFloat64(tag int) float64 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
@ -270,7 +270,7 @@ func (r *JceReader) ReadString(tag int) string {
if !r.skipToTag(tag) {
return ""
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 6:
return utils.B2S(r.readBytes(int(r.readByte())))
@ -285,7 +285,7 @@ func (r *JceReader) ReadBytes(tag int) []byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -306,7 +306,7 @@ func (r *JceReader) ReadByteArrArr(tag int) (baa [][]byte) {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -373,7 +373,7 @@ func (r *JceReader) ReadJceStruct(obj IJceStruct, tag int) {
if !r.skipToTag(tag) {
return
}
hd, _ := r.readHead()
hd := r.readHead()
if hd.Type != 10 {
return
}
@ -385,7 +385,7 @@ func (r *JceReader) ReadMapStrStr(tag int) map[string]string {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
@ -403,7 +403,7 @@ func (r *JceReader) ReadMapStrByte(tag int) map[string][]byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
@ -422,7 +422,7 @@ func (r *JceReader) ReadMapIntVipInfo(tag int) map[int]*VipInfo {
return nil
}
r.skipHead()
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
@ -447,7 +447,7 @@ func (r *JceReader) ReadMapStrMapStrByte(tag int) map[string]map[string][]byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
@ -512,7 +512,7 @@ func (r *JceReader) ReadFileStorageServerInfos(tag int) []FileStorageServerInfo
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -532,7 +532,7 @@ func (r *JceReader) ReadBigDataIPLists(tag int) []BigDataIPList {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -552,7 +552,7 @@ func (r *JceReader) ReadBigDataIPInfos(tag int) []BigDataIPInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -572,7 +572,7 @@ func (r *JceReader) ReadOnlineInfos(tag int) []OnlineInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -592,7 +592,7 @@ func (r *JceReader) ReadInstanceInfos(tag int) []InstanceInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -612,7 +612,7 @@ func (r *JceReader) ReadSsoServerInfos(tag int) []SsoServerInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -632,7 +632,7 @@ func (r *JceReader) ReadFriendInfos(tag int) []FriendInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -652,7 +652,7 @@ func (r *JceReader) ReadTroopNumbers(tag int) []TroopNumber {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -672,7 +672,7 @@ func (r *JceReader) ReadTroopMemberInfos(tag int) []TroopMemberInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -692,7 +692,7 @@ func (r *JceReader) ReadPushMessageInfos(tag int) []PushMessageInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
@ -712,7 +712,7 @@ func (r *JceReader) ReadSvcDevLoginInfos(tag int) []SvcDevLoginInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)

View File

@ -1,7 +1,7 @@
package jce
import (
"math/rand"
"crypto/rand"
"reflect"
"strconv"
"sync"

View File

@ -1,7 +1,7 @@
package binary
import (
"math/rand"
"crypto/rand"
"testing"
)

View File

@ -869,7 +869,7 @@ func (c *QQClient) buildGetMessageRequestPacket(flag msg.SyncFlag, msgTime int64
})
}
req := &msg.GetMessageRequest{
SyncFlag: proto.Some(int32(flag)),
SyncFlag: proto.Some(flag),
SyncCookie: cook,
LatestRambleNumber: proto.Int32(20),
OtherRambleNumber: proto.Int32(3),

View File

@ -145,10 +145,10 @@ func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams)
if pMsg.Body == nil || pMsg.Body.RichText == nil || pMsg.Body.RichText.Ptt == nil {
return
}
if len(pMsg.Body.RichText.Ptt.Reserve) != 0 {
// m := binary.NewReader(pMsg.Body.RichText.Ptt.Reserve[1:]).ReadTlvMap(1)
// T3 -> timestamp T8 -> voiceType T9 -> voiceLength T10 -> PbReserveStruct
}
// if len(pMsg.Body.RichText.Ptt.Reserve) != 0 {
// m := binary.NewReader(pMsg.Body.RichText.Ptt.Reserve[1:]).ReadTlvMap(1)
// T3 -> timestamp T8 -> voiceType T9 -> voiceLength T10 -> PbReserveStruct
//}
c.PrivateMessageEvent.dispatch(c, c.parsePrivateMessage(pMsg))
}

View File

@ -304,24 +304,6 @@ func genForwardTemplate(resID, preview, summary string, ts int64, items []*msg.P
}
}
func genLongTemplate(resID, brief string, ts int64) *message.ServiceElement {
limited := func() string {
if ss := []rune(brief); len(ss) > 30 {
return string(ss[:30]) + "…"
}
return brief
}()
template := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="35" templateID="1" action="viewMultiMsg" brief="%s" m_resid="%s" m_fileName="%d" sourceMsgId="0" url="" flag="3" adverSign="0" multiMsgFlag="1"> <item layout="1"> <title>%s</title> <hr hidden="false" style="0"/> <summary>点击查看完整消息</summary> </item> <source name="聊天记录" icon="" action="" appid="-1"/> </msg>`,
utils.XmlEscape(limited), resID, ts, utils.XmlEscape(limited),
)
return &message.ServiceElement{
Id: 35,
Content: template,
ResId: resID,
SubType: "Long",
}
}
func (c *QQClient) getWebDeviceInfo() (i string) {
qimei := strings.ToLower(utils.RandomString(36))
i += fmt.Sprintf("i=%v&imsi=&mac=%v&m=%v&o=%v&", c.device.IMEI, utils.B2S(c.device.MacAddress), utils.B2S(c.device.Device), utils.B2S(c.device.Version.Release))

View File

@ -250,7 +250,7 @@ func decodeGroupInfoResponse(c *QQClient, pkt *network.Packet) (any, error) {
func (c *QQClient) uploadGroupHeadPortrait(groupCode int64, img []byte) error {
url := fmt.Sprintf("http://htdata3.qq.com/cgi-bin/httpconn?htcmd=0x6ff0072&ver=5520&ukey=%v&range=0&uin=%v&seq=23&groupuin=%v&filetype=3&imagetype=5&userdata=0&subcmd=1&subver=101&clip=0_0_0_0&filesize=%v",
c.getSKey(), c.Uin, groupCode, len(img))
req, _ := http.NewRequest("POST", url, bytes.NewReader(img))
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(img))
req.Header["User-Agent"] = []string{"Dalvik/2.1.0 (Linux; U; Android 7.1.2; PCRT00 Build/N2G48H)"}
req.Header["Content-Type"] = []string{"multipart/form-data;boundary=****"}
rsp, err := http.DefaultClient.Do(req)

View File

@ -778,7 +778,7 @@ func decodeGuildPushFirstView(c *QQClient, pkt *network.Packet) (any, error) {
c.GuildService.Guilds = append(c.GuildService.Guilds, info)
}
}
if len(firstViewMsg.ChannelMsgs) > 0 { // sync msg
}
// if len(firstViewMsg.ChannelMsgs) > 0 { // sync msg
// }
return nil, nil
}

View File

@ -64,8 +64,8 @@ func decodeGuildEventFlowPacket(c *QQClient, pkt *network.Packet) (any, error) {
}
}
if m.Head.ContentHead.SubType.Unwrap() == 2 { // todo: tips?
if common == nil { // empty tips
}
// if common == nil { // empty tips
// }
tipsInfo := &tipsPushInfo{
TinyId: m.Head.RoutingHead.FromTinyid.Unwrap(),
GuildId: m.Head.RoutingHead.GuildId.Unwrap(),

View File

@ -241,7 +241,7 @@ func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
fw, _ := w.CreatePart(h)
_, _ = fw.Write(img)
_ = w.Close()
req, err := http.NewRequest("POST", "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf)
req, err := http.NewRequest(http.MethodPost, "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf)
if err != nil {
return nil, errors.Wrap(err, "new request error")
}

View File

@ -2,9 +2,9 @@ package auth
import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"encoding/json"
"math/rand"
"github.com/pkg/errors"

View File

@ -35,7 +35,7 @@ func CalcPow(data []byte) []byte {
}
ok = true
dst = tmp.Bytes()
elp = uint32(time.Now().Sub(start).Milliseconds())
elp = uint32(time.Since(start).Milliseconds())
}
w := binary.SelectWriter()

View File

@ -1,7 +1,6 @@
package highway
import (
binary2 "encoding/binary"
"fmt"
"net"
@ -13,15 +12,6 @@ type Addr struct {
Port int
}
func (a Addr) asTcpAddr() *net.TCPAddr {
addr := &net.TCPAddr{
IP: make([]byte, 4),
Port: a.Port,
}
binary2.LittleEndian.PutUint32(addr.IP, a.IP)
return addr
}
func (a Addr) AsNetIP() net.IP {
return net.IPv4(byte(a.IP>>24), byte(a.IP>>16), byte(a.IP>>8), byte(a.IP))
}

View File

@ -109,7 +109,7 @@ func uploadBDH(s *Session, addr Addr, trans *Transaction) ([]byte, error) {
if err != nil {
return nil, errors.Wrap(err, "write conn error")
}
rspHead, _, err := readResponse(reader)
rspHead, err := readResponse(reader)
if err != nil {
return nil, errors.Wrap(err, "highway upload error")
}
@ -210,7 +210,7 @@ func uploadBDHMultiThread(s *Session, addr Addr, trans *Transaction) ([]byte, er
if err != nil {
return errors.Wrap(err, "write conn error")
}
rspHead, _, err := readResponse(reader)
rspHead, err := readResponse(reader)
if err != nil {
return errors.Wrap(err, "highway upload error")
}

View File

@ -85,7 +85,7 @@ func (s *Session) Upload(addr Addr, trans Transaction) error {
if err != nil {
return errors.Wrap(err, "write conn error")
}
rspHead, _, err := readResponse(reader)
rspHead, err := readResponse(reader)
if err != nil {
return errors.Wrap(err, "highway upload error")
}
@ -130,7 +130,7 @@ func uploadExciting(s *Session, addr Addr, trans *Transaction) ([]byte, error) {
})
offset += int64(rl)
frame := newFrame(head, chunk)
req, _ := http.NewRequest("POST", url, &frame)
req, _ := http.NewRequest(http.MethodPost, url, &frame)
req.Header.Set("Accept", "*/*")
req.Header.Set("Connection", "Keep-Alive")
req.Header.Set("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")
@ -192,28 +192,28 @@ func (s *Session) sendEcho(conn net.Conn) error {
if err != nil {
return errors.Wrap(err, "echo error")
}
if _, _, err = readResponse(binary.NewNetworkReader(conn)); err != nil {
if _, err = readResponse(binary.NewNetworkReader(conn)); err != nil {
return errors.Wrap(err, "echo error")
}
return nil
}
func readResponse(r *binary.NetworkReader) (*pb.RspDataHighwayHead, []byte, error) {
func readResponse(r *binary.NetworkReader) (*pb.RspDataHighwayHead, error) {
_, err := r.ReadByte()
if err != nil {
return nil, nil, errors.Wrap(err, "failed to read byte")
return nil, errors.Wrap(err, "failed to read byte")
}
hl, _ := r.ReadInt32()
a2, _ := r.ReadInt32()
if hl > highwayMaxResponseSize || a2 > highwayMaxResponseSize {
return nil, nil, errors.Errorf("highway response invild. head size: %v body size: %v", hl, a2)
return nil, errors.Errorf("highway response invild. head size: %v body size: %v", hl, a2)
}
head, _ := r.ReadBytes(int(hl))
payload, _ := r.ReadBytes(int(a2))
_, _ = r.ReadBytes(int(a2)) // skip payload
_, _ = r.ReadByte()
rsp := new(pb.RspDataHighwayHead)
if err = proto.Unmarshal(head, rsp); err != nil {
return nil, nil, errors.Wrap(err, "failed to unmarshal protobuf message")
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
return rsp, payload, nil
return rsp, nil
}

View File

@ -2,7 +2,6 @@ package network
import (
"strconv"
"sync"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/internal/auth"
@ -10,10 +9,9 @@ import (
// Transport is a network transport.
type Transport struct {
sessionMu sync.Mutex
Sig *auth.SigInfo
Version *auth.AppVersion
Device *auth.Device
Sig *auth.SigInfo
Version *auth.AppVersion
Device *auth.Device
// connection
// conn *TCPClient

View File

@ -20,9 +20,7 @@ func (rm RecordMap) Exists(key int) bool {
return ok
}
var (
ErrMessageTooShort = errors.New("tlv: message too short")
)
var ErrMessageTooShort = errors.New("tlv: message too short")
// Decoder is a configurable TLV decoder.
type Decoder struct {

View File

@ -127,8 +127,7 @@ func (c *QQClient) msgGrayTipProcessor(groupCode int64, tipInfo *notify.AIOGrayT
}
}
// 好像只能这么判断
switch {
case strings.Contains(content, "头衔"):
if strings.Contains(content, "头衔") {
event := &MemberSpecialTitleUpdatedEvent{GroupCode: groupCode}
for _, cmd := range tipCmds {
if cmd.Command == 5 {
@ -185,6 +184,7 @@ func (e *MemberHonorChangedNotifyEvent) Content() string {
return fmt.Sprintf("%s(%d) 在群 %d 里连续发消息超过7天, 获得 群聊之火 标识。", e.Nick, e.Uin, e.GroupCode)
case Emotion:
return fmt.Sprintf("%s(%d) 在群聊 %d 中连续发表情包超过3天且累计数量超过20条获得 快乐源泉 标识。", e.Nick, e.Uin, e.GroupCode)
default:
return "ERROR"
}
return "ERROR"
}

View File

@ -129,7 +129,7 @@ func (c *QQClient) bigDataRequest(subCmd uint32, req proto.Message) ([]byte, err
tea := binary.NewTeaCipher(c.QiDian.bigDataReqSession.SessionKey)
body := tea.Encrypt(data)
url := fmt.Sprintf("http://%v/cgi-bin/httpconn", c.QiDian.bigDataReqAddrs[0])
httpReq, _ := http.NewRequest("POST", url, bytes.NewReader(binary.NewWriterF(func(w *binary.Writer) {
httpReq, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(binary.NewWriterF(func(w *binary.Writer) {
w.WriteByte(40)
w.WriteUInt32(uint32(len(head)))
w.WriteUInt32(uint32(len(body)))

View File

@ -169,7 +169,7 @@ func (c *QQClient) buildGetOfflineMsgRequestPacket() (uint16, []byte) {
}
flag := msg.SyncFlag_START
msgReq, _ := proto.Marshal(&msg.GetMessageRequest{
SyncFlag: proto.Some(int32(flag)),
SyncFlag: proto.Some(flag),
SyncCookie: c.sig.SyncCookie,
RambleFlag: proto.Int32(0),
ContextFlag: proto.Int32(1),
@ -232,7 +232,7 @@ func (c *QQClient) buildSyncMsgRequestPacket() (uint16, []byte) {
}
flag := msg.SyncFlag_START
msgReq := &msg.GetMessageRequest{
SyncFlag: proto.Some(int32(flag)),
SyncFlag: proto.Some(flag),
SyncCookie: c.sig.SyncCookie,
RambleFlag: proto.Int32(0),
ContextFlag: proto.Int32(1),

View File

@ -27,7 +27,7 @@ func (msg DynamicMessage) Encode() []byte {
key uint64
value any
}
var all []pair
all := make([]pair, len(msg))
for k, v := range msg {
all = append(all, pair{key: k, value: v})
}

View File

@ -28,7 +28,7 @@ func HttpGetBytes(url, cookie string) ([]byte, error) {
}
func HttpPostBytes(url string, data []byte) ([]byte, error) {
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(data))
if err != nil {
return nil, err
}
@ -58,7 +58,7 @@ func HttpPostBytesWithCookie(url string, data []byte, cookie string, contentType
if len(contentType) > 0 {
t = contentType[0]
}
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(data))
if err != nil {
return nil, err
}
@ -116,7 +116,7 @@ func (g *gzipCloser) Close() error {
// HTTPGetReadCloser 从 Http url 获取 io.ReadCloser
func HTTPGetReadCloser(url string, cookie string) (io.ReadCloser, error) {
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}