🎨 更新代码

This commit is contained in:
Yiwen-Chan
2021-06-29 19:07:10 +08:00
parent 04593e2147
commit f9f7fa08fb
9 changed files with 129 additions and 481 deletions

52
plugin_bilibili/info.go Normal file
View File

@@ -0,0 +1,52 @@
package fensi
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
zero.OnRegex(`^>bili info\s(.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
res, 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)
client := &http.Client{}
req, err := http.NewRequest("GET", 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)
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)
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"),
))
})
}

View File

@@ -0,0 +1,70 @@
package fensi
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
zero.OnRegex(`^>bili info\s?(.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
res, err := uid(keyword)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
id := res.Get("data.result.0.mid").Int()
// 获取详情
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)
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",
"数据获取时间: ", time.Now().Format("2006-01-02 15:04:05"),
))
})
}
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)
if err != nil {
return gjson.Result{}, err
}
if resp.StatusCode != http.StatusOK {
return gjson.Result{}, errors.New("code not 200")
}
data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
json := gjson.ParseBytes(data)
if json.Get("data.numResults").Int() == 0 {
return gjson.Result{}, errors.New("查无此人")
}
return json, nil
}