🎨 更新代码

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

View File

@ -85,11 +85,8 @@
- [x] 设置随机图片网址[url]
- [x] 太涩了(撤回最近发的图)
- [x] 评价图片:发送一张图片进行评分
- 关注bilibili的DD功能 `暂时失效`
- [x] /查 uid 通过uid查询成分与关注了2000uvp小号的共同关注
- [x] /查 name 通过名字查询成分与关注了2000uvp小号的共同关注
- [x] /粉丝 name查询粉丝实时数据/粉丝 嘉然)
- [x] /搜索 name通过名字查询用户uid
- bilibili `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili"`
- [x] >bili info [名字]
- 嘉然 `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana"`
- [x] @BOT 小作文
- [x] @BOT 发大病

View File

@ -1,107 +0,0 @@
package fensi
import (
"encoding/json"
"fmt"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"io/ioutil"
"net/http"
"strconv"
)
func init() {
zero.OnRegex(`^/查 (.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
uid := searchapi(keyword).Data.Result[0].Mid
if searchapi(keyword).Data.NumResults == 0 {
ctx.Send("名字没搜到")
return
}
accinfojson := accinfo(strconv.Itoa(uid))
hanjian := follow(strconv.Itoa(uid))
ctx.SendChain(message.Text(
"uid: ", accinfojson.Data.Mid, "\n",
"name: ", accinfojson.Data.Name, "\n",
"sex: ", accinfojson.Data.Sex, "\n",
"sign: ", accinfojson.Data.Sign, "\n",
"level: ", accinfojson.Data.Level, "\n",
"birthday: ", accinfojson.Data.Birthday, "\n",
"follow: ", gjson.Get(hanjian, "data.list.#.uname"),
))
})
}
func init() {
zero.OnRegex(`^/查UID:(.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
uid := ctx.State["regex_matched"].([]string)[1]
accinfojson := accinfo(uid)
hanjian := follow(uid)
status := accinfojson.Code
if status != 0 {
ctx.Send("UID非法")
return
}
ctx.SendChain(message.Text(
"uid: ", accinfojson.Data.Mid, "\n",
"name: ", accinfojson.Data.Name, "\n",
"sex: ", accinfojson.Data.Sex, "\n",
"sign: ", accinfojson.Data.Sign, "\n",
"level: ", accinfojson.Data.Level, "\n",
"birthday: ", accinfojson.Data.Birthday, "\n",
"follow: ", gjson.Get(hanjian, "data.list.#.uname"),
))
})
}
func accinfo(uid string) *accInfo {
url := "http://api.bilibili.com/x/space/acc/info?mid=" + uid
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result := &accInfo{}
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
panic(err)
}
return result
}
func follow(uid string) string {
url := "https://api.bilibili.com/x/relation/same/followings?vmid=" + uid
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
}
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")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
return string(body)
}

View File

@ -1,76 +0,0 @@
package fensi
import (
"encoding/json"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"net/http"
"strconv"
"time"
)
func init() {
zero.OnRegex(`^/粉丝 (.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
uid := searchapi(keyword).Data.Result[0].Mid
fensijson := fensiapi(strconv.Itoa(uid))
ctx.SendChain(message.Text(
"uid: ", fensijson.Mid, "\n",
"名字: ", fensijson.Uname, "\n",
"当前粉丝数: ", fensijson.Follower, "\n",
"24h涨粉数: ", fensijson.Rise, "\n",
"视频投稿数: ", fensijson.Video, "\n",
"直播间id: ", fensijson.Roomid, "\n",
"舰队: ", fensijson.GuardNum, "\n",
"直播总排名: ", fensijson.AreaRank, "\n",
"数据来源: ", "https://vtbs.moe/detail/", uid, "\n",
"数据获取时间: ", timeStamp(),
))
})
}
func init() {
zero.OnRegex(`^/info (.{1,25})$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
uid := searchapi(keyword).Data.Result[0].Mid
fensijson := fensiapi(strconv.Itoa(uid))
ctx.SendChain(message.Text(
"uid: ", fensijson.Mid, "\n",
"名字: ", fensijson.Uname, "\n",
"当前粉丝数: ", fensijson.Follower, "\n",
"24h涨粉数: ", fensijson.Rise, "\n",
"视频投稿数: ", fensijson.Video, "\n",
"直播间id: ", fensijson.Roomid, "\n",
"舰队: ", fensijson.GuardNum, "\n",
"直播总排名: ", fensijson.AreaRank, "\n",
"数据来源: ", "https://vtbs.moe/detail/", uid, "\n",
"数据获取时间: ", timeStamp(),
))
})
}
func fensiapi(uid string) *follower {
url := "https://api.vtbs.moe/v1/detail/" + uid
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result := &follower{}
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
panic(err)
}
return result
}
func timeStamp() string{
unixtime := time.Now().Unix()
timestamp := time.Unix(unixtime, 0)
return timestamp.Format("2006-01-02 15:04:05")
}

View File

@ -1,57 +0,0 @@
package fensi
import (
"encoding/json"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"net/http"
)
func init() {
zero.OnRegex(`^/搜索 (.*)$`).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
searchJson := searchapi(keyword)
if searchapi(keyword).Data.NumResults == 0 {
ctx.Send("名字没搜到")
return
}
if searchapi(keyword).Data.NumResults < 5 {
ctx.SendChain(message.Text(
"uid ", searchJson.Data.Result[0].Mid, "\n",
"name ", searchJson.Data.Result[0].Uname, "\n",
))
return
}
ctx.SendChain(message.Text(
"搜索结果很多请尽量准确关键字以下为你返回前5条结果", "\n\n",
"uid1 ", searchJson.Data.Result[0].Mid, "\n",
"name1 ", searchJson.Data.Result[0].Uname, "\n\n",
"uid2 ", searchJson.Data.Result[1].Mid, "\n",
"name2: ", searchJson.Data.Result[1].Uname, "\n\n",
"uid3: ", searchJson.Data.Result[2].Mid, "\n",
"name3: ", searchJson.Data.Result[2].Uname, "\n\n",
"uid4: ", searchJson.Data.Result[3].Mid, "\n",
"name4: ", searchJson.Data.Result[3].Uname, "\n\n",
"uid5: ", searchJson.Data.Result[4].Mid, "\n",
"name5: ", searchJson.Data.Result[4].Uname,
))
})
}
func searchapi(keyword string) *search {
url := "http://api.bilibili.com/x/web-interface/search/type?search_type=bili_user&&user_type=1&keyword=" + keyword
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result := &search{}
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
panic(err)
}
return result
}

View File

@ -1,235 +0,0 @@
package fensi
// 搜索api的json结构体
type search struct {
Code int `json:"code"`
Message string `json:"message"`
TTL int `json:"ttl"`
Data struct {
Seid string `json:"seid"`
Page int `json:"page"`
Pagesize int `json:"pagesize"`
NumResults int `json:"numResults"`
NumPages int `json:"numPages"`
SuggestKeyword string `json:"suggest_keyword"`
RqtType string `json:"rqt_type"`
CostTime struct {
ParamsCheck string `json:"params_check"`
GetUpuserLiveStatus string `json:"get upuser live status"`
IllegalHandler string `json:"illegal_handler"`
AsResponseFormat string `json:"as_response_format"`
AsRequest string `json:"as_request"`
SaveCache string `json:"save_cache"`
DeserializeResponse string `json:"deserialize_response"`
AsRequestFormat string `json:"as_request_format"`
Total string `json:"total"`
MainHandler string `json:"main_handler"`
} `json:"cost_time"`
ExpList interface{} `json:"exp_list"`
EggHit int `json:"egg_hit"`
Result []struct {
Type string `json:"type"`
Mid int `json:"mid"`
Uname string `json:"uname"`
Usign string `json:"usign"`
Fans int `json:"fans"`
Videos int `json:"videos"`
Upic string `json:"upic"`
VerifyInfo string `json:"verify_info"`
Level int `json:"level"`
Gender int `json:"gender"`
IsUpuser int `json:"is_upuser"`
IsLive int `json:"is_live"`
RoomID int `json:"room_id"`
Res []struct {
Aid int `json:"aid"`
Bvid string `json:"bvid"`
Title string `json:"title"`
Pubdate int `json:"pubdate"`
Arcurl string `json:"arcurl"`
Pic string `json:"pic"`
Play string `json:"play"`
Dm int `json:"dm"`
Coin int `json:"coin"`
Fav int `json:"fav"`
Desc string `json:"desc"`
Duration string `json:"duration"`
IsPay int `json:"is_pay"`
IsUnionVideo int `json:"is_union_video"`
} `json:"res"`
OfficialVerify struct {
Type int `json:"type"`
Desc string `json:"desc"`
} `json:"official_verify"`
HitColumns []interface{} `json:"hit_columns"`
} `json:"result"`
ShowColumn int `json:"show_column"`
} `json:"data"`
}
// 账号信息api的json结构体
type accInfo struct {
Code int `json:"code"`
Message string `json:"message"`
TTL int `json:"ttl"`
Data struct {
Mid int `json:"mid"`
Name string `json:"name"`
Sex string `json:"sex"`
Face string `json:"face"`
Sign string `json:"sign"`
Rank int `json:"rank"`
Level int `json:"level"`
Jointime int `json:"jointime"`
Moral int `json:"moral"`
Silence int `json:"silence"`
Birthday string `json:"birthday"`
Coins int `json:"coins"`
FansBadge bool `json:"fans_badge"`
Official struct {
Role int `json:"role"`
Title string `json:"title"`
Desc string `json:"desc"`
Type int `json:"type"`
} `json:"official"`
Vip struct {
Type int `json:"type"`
Status int `json:"status"`
DueDate int64 `json:"due_date"`
VipPayType int `json:"vip_pay_type"`
ThemeType int `json:"theme_type"`
Label struct {
Path string `json:"path"`
Text string `json:"text"`
LabelTheme string `json:"label_theme"`
TextColor string `json:"text_color"`
BgStyle int `json:"bg_style"`
BgColor string `json:"bg_color"`
BorderColor string `json:"border_color"`
} `json:"label"`
AvatarSubscript int `json:"avatar_subscript"`
NicknameColor string `json:"nickname_color"`
Role int `json:"role"`
AvatarSubscriptURL string `json:"avatar_subscript_url"`
} `json:"vip"`
Pendant struct {
Pid int `json:"pid"`
Name string `json:"name"`
Image string `json:"image"`
Expire int `json:"expire"`
ImageEnhance string `json:"image_enhance"`
ImageEnhanceFrame string `json:"image_enhance_frame"`
} `json:"pendant"`
Nameplate struct {
Nid int `json:"nid"`
Name string `json:"name"`
Image string `json:"image"`
ImageSmall string `json:"image_small"`
Level string `json:"level"`
Condition string `json:"condition"`
} `json:"nameplate"`
UserHonourInfo struct {
Mid int `json:"mid"`
Colour interface{} `json:"colour"`
Tags interface{} `json:"tags"`
} `json:"user_honour_info"`
IsFollowed bool `json:"is_followed"`
TopPhoto string `json:"top_photo"`
Theme struct {
} `json:"theme"`
SysNotice struct {
} `json:"sys_notice"`
LiveRoom struct {
RoomStatus int `json:"roomStatus"`
LiveStatus int `json:"liveStatus"`
URL string `json:"url"`
Title string `json:"title"`
Cover string `json:"cover"`
Online int `json:"online"`
Roomid int `json:"roomid"`
RoundStatus int `json:"roundStatus"`
BroadcastType int `json:"broadcast_type"`
} `json:"live_room"`
} `json:"data"`
}
//共同关注api的json结构体
type followings struct {
Code int `json:"code"`
Message string `json:"message"`
TTL int `json:"ttl"`
Data struct {
List []struct {
Mid int `json:"mid"`
Attribute int `json:"attribute"`
Mtime int `json:"mtime"`
Tag interface{} `json:"tag"`
Special int `json:"special"`
ContractInfo struct {
IsContractor bool `json:"is_contractor"`
Ts int `json:"ts"`
IsContract bool `json:"is_contract"`
} `json:"contract_info"`
Uname string `json:"uname"`
Face string `json:"face"`
Sign string `json:"sign"`
OfficialVerify struct {
Type int `json:"type"`
Desc string `json:"desc"`
} `json:"official_verify"`
Vip struct {
VipType int `json:"vipType"`
VipDueDate int64 `json:"vipDueDate"`
DueRemark string `json:"dueRemark"`
AccessStatus int `json:"accessStatus"`
VipStatus int `json:"vipStatus"`
VipStatusWarn string `json:"vipStatusWarn"`
ThemeType int `json:"themeType"`
Label struct {
Path string `json:"path"`
Text string `json:"text"`
LabelTheme string `json:"label_theme"`
TextColor string `json:"text_color"`
BgStyle int `json:"bg_style"`
BgColor string `json:"bg_color"`
BorderColor string `json:"border_color"`
} `json:"label"`
AvatarSubscript int `json:"avatar_subscript"`
NicknameColor string `json:"nickname_color"`
AvatarSubscriptURL string `json:"avatar_subscript_url"`
} `json:"vip"`
} `json:"list"`
ReVersion int64 `json:"re_version"`
Total int `json:"total"`
} `json:"data"`
}
// 粉丝信息api的json结构体
type follower struct {
Mid int `json:"mid"`
UUID string `json:"uuid"`
Uname string `json:"uname"`
Video int `json:"video"`
Roomid int `json:"roomid"`
Sign string `json:"sign"`
Notice string `json:"notice"`
Face string `json:"face"`
Rise int `json:"rise"`
TopPhoto string `json:"topPhoto"`
ArchiveView int `json:"archiveView"`
Follower int `json:"follower"`
LiveStatus int `json:"liveStatus"`
RecordNum int `json:"recordNum"`
GuardNum int `json:"guardNum"`
LastLive struct {
Online int `json:"online"`
Time int64 `json:"time"`
} `json:"lastLive"`
GuardChange int `json:"guardChange"`
GuardType []int `json:"guardType"`
AreaRank int `json:"areaRank"`
Online int `json:"online"`
Title string `json:"title"`
Time int64 `json:"time"`
LiveStartTime int `json:"liveStartTime"`
}

View File

@ -21,7 +21,8 @@ import (
//_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片
// 嘉然相关
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" //
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病
// 二次元图片
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片

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
}

View File

@ -37,15 +37,18 @@ func init() {
resp, err := http.Get(API)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
continue
}
if resp.StatusCode != http.StatusOK {
ctx.SendChain(message.Text("ERROR: code ", resp.StatusCode))
continue
}
data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
json := gjson.ParseBytes(data)
if e := json.Get("error").Str; e != "" {
ctx.SendChain(message.Text("ERROR: ", e))
continue
}
url := json.Get("data.0.urls.original").Str
ctx.SendGroupMessage(0, message.Image(url))