Skip to content

Commit

Permalink
fix: get group honor info (#340)
Browse files Browse the repository at this point in the history
* fix: get group honor info

* update: use newDecoder instead manual parse
  • Loading branch information
1umine authored Aug 23, 2023
1 parent e4b6dc6 commit a8213e1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client/http_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/textproto"
"net/url"
"regexp"
"strconv"

"github.com/pkg/errors"
Expand Down Expand Up @@ -59,15 +60,20 @@ const (
Emotion HonorType = 6 // 快乐源泉
)

// 匹配 window.__INITIAL_STATE__ = 后的内容
var honorRe = regexp.MustCompile(`window\.__INITIAL_STATE__\s*?=\s*?(\{.*\})`)

func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*GroupHonorInfo, error) {
b, err := utils.HttpGetBytes(fmt.Sprintf("https://qun.qq.com/interactive/honorlist?gc=%d&type=%d", groupCode, honorType), c.getCookiesWithDomain("qun.qq.com"))
if err != nil {
return nil, err
}
b = b[bytes.Index(b, []byte(`window.__INITIAL_STATE__=`))+25:]
b = b[:bytes.Index(b, []byte("</script>"))]
matched := honorRe.FindSubmatch(b)
if len(matched) == 0 {
return nil, errors.New("无匹配结果")
}
ret := GroupHonorInfo{}
err = json.Unmarshal(b, &ret)
err = json.NewDecoder(bytes.NewReader(matched[1])).Decode(&ret)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a8213e1

Please sign in to comment.