1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

client: remove some err check

`(*bytes.Buffer).Write` always return nil error, so we don't need error check
This commit is contained in:
wdvxdr 2022-03-19 10:03:10 +08:00
parent 2dfc8f0cbc
commit 5903226f25
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
6 changed files with 13 additions and 38 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html" "html"
"io"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/textproto" "net/textproto"
@ -158,7 +157,6 @@ type noticeImage struct {
} }
func (c *QQClient) GetGroupNotice(groupCode int64) (l []*GroupNoticeMessage, err error) { func (c *QQClient) GetGroupNotice(groupCode int64) (l []*GroupNoticeMessage, err error) {
v := url.Values{} v := url.Values{}
v.Set("bkn", strconv.Itoa(c.getCSRFToken())) v.Set("bkn", strconv.Itoa(c.getCSRFToken()))
v.Set("qid", strconv.FormatInt(groupCode, 10)) v.Set("qid", strconv.FormatInt(groupCode, 10))
@ -220,33 +218,15 @@ func (c *QQClient) parseGroupNoticeJson(s *groupNoticeRsp) []*GroupNoticeMessage
func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) { func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
w := multipart.NewWriter(buf) w := multipart.NewWriter(buf)
err := w.WriteField("bkn", strconv.Itoa(c.getCSRFToken())) _ = w.WriteField("bkn", strconv.Itoa(c.getCSRFToken()))
if err != nil { _ = w.WriteField("source", "troopNotice")
return nil, errors.Wrap(err, "write multipart<bkn> failed") _ = w.WriteField("m", "0")
}
err = w.WriteField("source", "troopNotice")
if err != nil {
return nil, errors.Wrap(err, "write multipart<source> failed")
}
err = w.WriteField("m", "0")
if err != nil {
return nil, errors.Wrap(err, "write multipart<m> failed")
}
h := make(textproto.MIMEHeader) h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", `form-data; name="pic_up"; filename="temp_uploadFile.png"`) h.Set("Content-Disposition", `form-data; name="pic_up"; filename="temp_uploadFile.png"`)
h.Set("Content-Type", "image/png") h.Set("Content-Type", "image/png")
fw, err := w.CreatePart(h) fw, _ := w.CreatePart(h)
if err != nil { _, _ = fw.Write(img)
return nil, errors.Wrap(err, "create multipart field<pic_up> failed") _ = w.Close()
}
_, err = fw.Write(img)
if err != nil {
return nil, errors.Wrap(err, "write multipart<pic_up> failed")
}
err = w.Close()
if err != nil {
return nil, errors.Wrap(err, "close multipart failed")
}
req, err := http.NewRequest("POST", "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf) req, err := http.NewRequest("POST", "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "new request error") return nil, errors.Wrap(err, "new request error")
@ -258,12 +238,8 @@ func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
return nil, errors.Wrap(err, "post error") return nil, errors.Wrap(err, "post error")
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(resp.Body) var res noticePicUpResponse
if err != nil { err = json.NewDecoder(resp.Body).Decode(&res)
return nil, errors.Wrap(err, "read body error")
}
res := noticePicUpResponse{}
err = json.Unmarshal(body, &res)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal json") return nil, errors.Wrap(err, "failed to unmarshal json")
} }

View File

@ -329,7 +329,6 @@ func (c *QQClient) uploadOcrImage(img io.Reader, size int32, sum []byte) (string
Sum: sum, Sum: sum,
Ticket: c.highwaySession.SigSession, Ticket: c.highwaySession.SigSession,
Ext: ext, Ext: ext,
Encrypt: false,
}) })
if err != nil { if err != nil {
return "", errors.Wrap(err, "upload ocr image error") return "", errors.Wrap(err, "upload ocr image error")

View File

@ -192,7 +192,6 @@ func (c *QQClient) buildGroupTempSendingPacket(groupUin, target int64, msgSeq, r
} }
func (c *QQClient) buildWPATempSendingPacket(uin int64, sig []byte, msgSeq, r int32, time int64, m *message.SendingMessage) (uint16, []byte) { func (c *QQClient) buildWPATempSendingPacket(uin int64, sig []byte, msgSeq, r int32, time int64, m *message.SendingMessage) (uint16, []byte) {
req := &msg.SendMessageRequest{ req := &msg.SendMessageRequest{
RoutingHead: &msg.RoutingHead{WpaTmp: &msg.WPATmp{ RoutingHead: &msg.RoutingHead{WpaTmp: &msg.WPATmp{
ToUin: proto.Uint64(uint64(uin)), ToUin: proto.Uint64(uint64(uin)),

View File

@ -79,7 +79,6 @@ func (c *QQClient) UploadVoice(target message.Source, voice io.ReadSeeker) (*mes
Size: length, Size: length,
Ticket: c.highwaySession.SigSession, Ticket: c.highwaySession.SigSession,
Ext: ext, Ext: ext,
Encrypt: false,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -103,8 +103,10 @@ type AnimatedSticker struct {
Name string Name string
} }
type RedBagMessageType int type (
type AtType int RedBagMessageType int
AtType int
)
// /com/tencent/mobileqq/data/MessageForQQWalletMsg.java // /com/tencent/mobileqq/data/MessageForQQWalletMsg.java
const ( const (

View File

@ -778,7 +778,7 @@ func splitPlainMessage(content string) []IMessageElement {
} }
} }
if last != len(content) { if last != len(content) {
splittedMessage = append(splittedMessage, NewText(content[last:len(content)])) splittedMessage = append(splittedMessage, NewText(content[last:]))
} }
return splittedMessage return splittedMessage