Skip to content

Commit

Permalink
feat: 删除公告
Browse files Browse the repository at this point in the history
feat: 获取公告现在会返回notice_id(fid) 用来删除公告
fix: “发送给新成员”的公告无法正常获取
  • Loading branch information
Akegarasu committed Jun 30, 2022
1 parent e26832b commit af13584
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions client/http_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,22 @@ func (c *QQClient) GetTts(text string) ([]byte, error) {
/* -------- GroupNotice -------- */

type groupNoticeRsp struct {
Feeds []*struct {
SenderId uint32 `json:"u"`
PublishTime uint64 `json:"pubt"`
Message struct {
Text string `json:"text"`
Images []noticeImage `json:"pics"`
} `json:"msg"`
} `json:"feeds"`
Feeds []*GroupNoticeFeed `json:"feeds"`
Inst []*GroupNoticeFeed `json:"inst"`
}

type GroupNoticeFeed struct {
NoticeId string `json:"fid"`
SenderId uint32 `json:"u"`
PublishTime uint64 `json:"pubt"`
Message struct {
Text string `json:"text"`
Images []noticeImage `json:"pics"`
} `json:"msg"`
}

type GroupNoticeMessage struct {
NoticeId string `json:"notice_id"`
SenderId uint32 `json:"sender_id"`
PublishTime uint64 `json:"publish_time"`
Message struct {
Expand Down Expand Up @@ -187,9 +192,8 @@ func (c *QQClient) GetGroupNotice(groupCode int64) (l []*GroupNoticeMessage, err
}

func (c *QQClient) parseGroupNoticeJson(s *groupNoticeRsp) []*GroupNoticeMessage {
o := make([]*GroupNoticeMessage, 0, len(s.Feeds))
for _, v := range s.Feeds {

o := make([]*GroupNoticeMessage, 0, len(s.Feeds)+len(s.Inst))
parse := func(v *GroupNoticeFeed) {
ims := make([]GroupNoticeImage, 0, len(v.Message.Images))
for i := 0; i < len(v.Message.Images); i++ {
ims = append(ims, GroupNoticeImage{
Expand All @@ -200,6 +204,7 @@ func (c *QQClient) parseGroupNoticeJson(s *groupNoticeRsp) []*GroupNoticeMessage
}

o = append(o, &GroupNoticeMessage{
NoticeId: v.NoticeId,
SenderId: v.SenderId,
PublishTime: v.PublishTime,
Message: struct {
Expand All @@ -211,7 +216,12 @@ func (c *QQClient) parseGroupNoticeJson(s *groupNoticeRsp) []*GroupNoticeMessage
},
})
}

for _, v := range s.Feeds {
parse(v)
}
for _, v := range s.Inst {
parse(v)
}
return o
}

Expand Down Expand Up @@ -277,3 +287,12 @@ func (c *QQClient) AddGroupNoticeWithPic(groupCode int64, text string, pic []byt
}
return nil
}

func (c *QQClient) DelGroupNotice(groupCode int64, fid string) error {
body := fmt.Sprintf(`fid=%s&qid=%v&bkn=%v&ft=23&op=1`, fid, groupCode, c.getCSRFToken())
_, err := utils.HttpPostBytesWithCookie("https://web.qun.qq.com/cgi-bin/announce/del_feed", []byte(body), c.getCookiesWithDomain("qun.qq.com"))
if err != nil {
return errors.Wrap(err, "request error")
}
return nil
}

0 comments on commit af13584

Please sign in to comment.