From f8ccb467bac89f59451adbfb37e46e0fd7ed76e6 Mon Sep 17 00:00:00 2001 From: Suika99 <290760339@qq.com> Date: Fri, 2 Jul 2021 19:06:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E4=BA=86=E4=B8=AAbody=E5=8C=85?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA=E7=9A=84bug=EF=BC=8C?= =?UTF-8?q?=E8=99=BD=E7=84=B6=E4=B8=8D=E7=9F=A5=E9=81=93=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E4=BA=86=E5=95=A5=EF=BC=8C=E4=BD=86=E5=AE=83=E7=A1=AE=E5=AE=9E?= =?UTF-8?q?=E6=98=AF=E8=A2=AB=E4=BF=AE=E5=A5=BD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 70 +++++++++++++++++++++++++++++++++--- plugin_ai_false/ai_false.go | 2 +- plugin_bilibili/fansDaily.go | 14 ++++---- plugin_bilibili/info.go | 41 ++++++++++----------- plugin_bilibili/live_info.go | 37 +++++++------------ 5 files changed, 108 insertions(+), 56 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fd386a1b..232c490e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,13 +1,19 @@ - + + + + + + + - + @@ -26,7 +32,12 @@ - + + + + + + @@ -38,7 +49,16 @@ - + + + + + + + + + + @@ -48,8 +68,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -58,6 +108,18 @@ + + + true diff --git a/plugin_ai_false/ai_false.go b/plugin_ai_false/ai_false.go index b0421852..0dffa3f6 100644 --- a/plugin_ai_false/ai_false.go +++ b/plugin_ai_false/ai_false.go @@ -16,7 +16,7 @@ import ( ) func init() { // 插件主体 - zero.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission). + zero.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}). Handle(func(ctx *zero.Ctx) { ctx.SendChain(message.Text( "* CPU占用率: ", getCpuPercent(), "%\n", diff --git a/plugin_bilibili/fansDaily.go b/plugin_bilibili/fansDaily.go index 7a1f97a7..84321c91 100644 --- a/plugin_bilibili/fansDaily.go +++ b/plugin_bilibili/fansDaily.go @@ -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, @@ -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) @@ -117,4 +117,4 @@ func fensiapi(uid string) *follower { panic(err) } return result -} \ No newline at end of file +} diff --git a/plugin_bilibili/info.go b/plugin_bilibili/info.go index c394cb88..fd3b7042 100644 --- a/plugin_bilibili/info.go +++ b/plugin_bilibili/info.go @@ -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"), )) }) } diff --git a/plugin_bilibili/live_info.go b/plugin_bilibili/live_info.go index 68b348ff..60845cb6 100644 --- a/plugin_bilibili/live_info.go +++ b/plugin_bilibili/live_info.go @@ -2,7 +2,6 @@ package plugin_bilibili import ( "errors" - "fmt" "io/ioutil" "net/http" "time" @@ -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) { @@ -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)