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:
parent
2dfc8f0cbc
commit
5903226f25
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
@ -158,7 +157,6 @@ type noticeImage struct {
|
||||
}
|
||||
|
||||
func (c *QQClient) GetGroupNotice(groupCode int64) (l []*GroupNoticeMessage, err error) {
|
||||
|
||||
v := url.Values{}
|
||||
v.Set("bkn", strconv.Itoa(c.getCSRFToken()))
|
||||
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) {
|
||||
buf := new(bytes.Buffer)
|
||||
w := multipart.NewWriter(buf)
|
||||
err := w.WriteField("bkn", strconv.Itoa(c.getCSRFToken()))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "write multipart<bkn> failed")
|
||||
}
|
||||
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")
|
||||
}
|
||||
_ = w.WriteField("bkn", strconv.Itoa(c.getCSRFToken()))
|
||||
_ = w.WriteField("source", "troopNotice")
|
||||
_ = w.WriteField("m", "0")
|
||||
h := make(textproto.MIMEHeader)
|
||||
h.Set("Content-Disposition", `form-data; name="pic_up"; filename="temp_uploadFile.png"`)
|
||||
h.Set("Content-Type", "image/png")
|
||||
fw, err := w.CreatePart(h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "create multipart field<pic_up> failed")
|
||||
}
|
||||
_, 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")
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "read body error")
|
||||
}
|
||||
res := noticePicUpResponse{}
|
||||
err = json.Unmarshal(body, &res)
|
||||
var res noticePicUpResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to unmarshal json")
|
||||
}
|
||||
|
@ -329,7 +329,6 @@ func (c *QQClient) uploadOcrImage(img io.Reader, size int32, sum []byte) (string
|
||||
Sum: sum,
|
||||
Ticket: c.highwaySession.SigSession,
|
||||
Ext: ext,
|
||||
Encrypt: false,
|
||||
})
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "upload ocr image error")
|
||||
|
@ -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) {
|
||||
|
||||
req := &msg.SendMessageRequest{
|
||||
RoutingHead: &msg.RoutingHead{WpaTmp: &msg.WPATmp{
|
||||
ToUin: proto.Uint64(uint64(uin)),
|
||||
|
@ -79,7 +79,6 @@ func (c *QQClient) UploadVoice(target message.Source, voice io.ReadSeeker) (*mes
|
||||
Size: length,
|
||||
Ticket: c.highwaySession.SigSession,
|
||||
Ext: ext,
|
||||
Encrypt: false,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -103,8 +103,10 @@ type AnimatedSticker struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type RedBagMessageType int
|
||||
type AtType int
|
||||
type (
|
||||
RedBagMessageType int
|
||||
AtType int
|
||||
)
|
||||
|
||||
// /com/tencent/mobileqq/data/MessageForQQWalletMsg.java
|
||||
const (
|
||||
|
@ -778,7 +778,7 @@ func splitPlainMessage(content string) []IMessageElement {
|
||||
}
|
||||
}
|
||||
if last != len(content) {
|
||||
splittedMessage = append(splittedMessage, NewText(content[last:len(content)]))
|
||||
splittedMessage = append(splittedMessage, NewText(content[last:]))
|
||||
}
|
||||
|
||||
return splittedMessage
|
||||
|
Loading…
x
Reference in New Issue
Block a user