Skip to content

Commit

Permalink
Merge pull request FloatTech#42 from Suika99/master
Browse files Browse the repository at this point in the history
解决返回body包数据为空的问题
  • Loading branch information
kanrichan authored Jul 2, 2021
2 parents eb08d29 + 098e81d commit 760e633
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 51 deletions.
124 changes: 124 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions plugin_bilibili/fansDaily.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func FansDaily(groupID int64) {
func fansData(groupID int64) {
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
var (
diana = fensiapi("672328094")
ava = fensiapi("672346917")
eileen = fensiapi("672342685")
bella = fensiapi("672353429")
carol = fensiapi("351609538")
diana = fansapi("672328094")
ava = fansapi("672346917")
eileen = fansapi("672342685")
bella = fansapi("672353429")
carol = fansapi("351609538")
)
ctx.SendGroupMessage(
groupID,
Expand Down Expand Up @@ -104,7 +104,7 @@ func fansData(groupID int64) {
}

// 请求api
func fensiapi(uid string) *follower {
func fansapi(uid string) *follower {

url := "https://api.vtbs.moe/v1/detail/" + uid
resp, err := http.Get(url)
Expand All @@ -117,4 +117,4 @@ func fensiapi(uid string) *follower {
panic(err)
}
return result
}
}
41 changes: 21 additions & 20 deletions plugin_bilibili/info.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
package plugin_bilibili

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"io/ioutil"
"net/http"
)

// 查成分的
func init() {
zero.OnRegex(`^>user info\s(.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
res, err := uid(keyword)
rest, err := uid(keyword)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
id := res.Get("data.result.0.mid").Int()
url := fmt.Sprintf("https://api.bilibili.com/x/relation/same/followings?vmid=%d", id)
id := rest.Get("data.result.0.mid").String()
url := "https://api.bilibili.com/x/relation/same/followings?vmid=" + id
method := "GET"
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(method, url, nil)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
req.Header.Add("cookie", "CURRENT_FNVAL=80; _uuid=772B88E8-3ED1-D589-29BB-F6CB5214239A06137infoc; blackside_state=1; bfe_id=6f285c892d9d3c1f8f020adad8bed553; rpdid=|(umY~Jkl|kJ0J'uYkR|)lu|); fingerprint=0ec2b1140fb30b56d7b5e415bc3b5fb1; buvid_fp=C91F5265-3DF4-4D5A-9FF3-C546370B14C0143096infoc; buvid_fp_plain=C91F5265-3DF4-4D5A-9FF3-C546370B14C0143096infoc; SESSDATA=9e0266f6%2C1639637127%2Cb0172%2A61; bili_jct=96ddbd7e22d527abdc0501339a12d4d3; DedeUserID=695737880; DedeUserID__ckMd5=0117660e75db7b01; sid=5labuhaf; PVID=1; bfe_id=1e33d9ad1cb29251013800c68af42315")
resp, err := client.Do(req)
res, err := client.Do(req)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ctx.SendChain(message.Text("ERROR: code ", resp.StatusCode))
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
data, _ := ioutil.ReadAll(resp.Body)
json := gjson.ParseBytes(data)
data := string(body)
ctx.SendChain(message.Text(
"uid: ", res.Get("data.result.0.mid").Int(), "\n",
"name: ", res.Get("data.result.0.uname").Str, "\n",
"sex: ", []string{"", "", "女", "男"}[res.Get("data.result.0.gender").Int()], "\n",
"sign: ", res.Get("data.result.0.usign").Str, "\n",
"level: ", res.Get("data.result.0.level").Int(), "\n",
"follow: ", json.Get("data.list.#.uname"),
"uid: ", rest.Get("data.result.0.mid").Int(), "\n",
"name: ", rest.Get("data.result.0.uname").Str, "\n",
"sex: ", []string{"", "", "女", "男"}[rest.Get("data.result.0.gender").Int()], "\n",
"sign: ", rest.Get("data.result.0.usign").Str, "\n",
"level: ", rest.Get("data.result.0.level").Int(), "\n",
"follow: ", gjson.Get(data, "data.list.#.uname"),
))
})
}
37 changes: 13 additions & 24 deletions plugin_bilibili/live_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package plugin_bilibili

import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"time"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
)

// 查vup粉丝数据
func init() {
zero.OnRegex(`^>vup info\s?(.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
Expand All @@ -21,36 +21,25 @@ func init() {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
id := res.Get("data.result.0.mid").Int()
id := res.Get("data.result.0.mid").String()
// 获取详情
api := fmt.Sprintf("https://api.vtbs.moe/v1/detail/%d", id)
resp, err := http.Get(api)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
ctx.SendChain(message.Text("ERROR: code ", resp.StatusCode))
return
}
data, _ := ioutil.ReadAll(resp.Body)
json := gjson.ParseBytes(data)
json := fansapi(id)
ctx.SendChain(message.Text(
"uid: ", json.Get("mid").Int(), "\n",
"名字: ", json.Get("uname").Str, "\n",
"当前粉丝数: ", json.Get("follower").Int(), "\n",
"24h涨粉数: ", json.Get("rise").Int(), "\n",
"视频投稿数: ", json.Get("video").Int(), "\n",
"直播间id: ", json.Get("roomid").Int(), "\n",
"舰队: ", json.Get("guardNum").Int(), "\n",
"直播总排名: ", json.Get("areaRank").Int(), "\n",
"数据来源: ", "https://vtbs.moe/detail/", uid, "\n",
"uid: ", json.Mid, "\n",
"名字: ", json.Uname, "\n",
"当前粉丝数: ", json.Follower, "\n",
"24h涨粉数: ", json.Rise, "\n",
"视频投稿数: ", json.Video, "\n",
"直播间id: ", json.Roomid, "\n",
"舰队: ", json.GuardNum, "\n",
"直播总排名: ", json.AreaRank, "\n",
"数据来源: ", "https://vtbs.moe/detail/", json.Mid, "\n",
"数据获取时间: ", time.Now().Format("2006-01-02 15:04:05"),
))
})
}

// 搜索api:通过把触发指令传入的昵称找出uid返回
func uid(keyword string) (gjson.Result, error) {
api := "http://api.bilibili.com/x/web-interface/search/type?search_type=bili_user&&user_type=1&keyword=" + keyword
resp, err := http.Get(api)
Expand Down

0 comments on commit 760e633

Please sign in to comment.