mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
🎨 优化目录结构
This commit is contained in:
165
plugin/bilibili/fansDaily.go
Normal file
165
plugin/bilibili/fansDaily.go
Normal file
@@ -0,0 +1,165 @@
|
||||
package bilibili
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
)
|
||||
|
||||
type follower struct {
|
||||
Mid int `json:"mid"`
|
||||
Uname string `json:"uname"`
|
||||
Video int `json:"video"`
|
||||
Roomid int `json:"roomid"`
|
||||
Rise int `json:"rise"`
|
||||
Follower int `json:"follower"`
|
||||
GuardNum int `json:"guardNum"`
|
||||
AreaRank int `json:"areaRank"`
|
||||
}
|
||||
|
||||
// 开启日报推送
|
||||
func init() {
|
||||
fansDaily()
|
||||
en := control.Register("fansdaily", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: true,
|
||||
Help: "fansdaily\n- /开启粉丝日报\n- /关闭粉丝日报",
|
||||
})
|
||||
zero.OnCommand("开启粉丝日报", zero.AdminPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
m, ok := control.Lookup("fansdaily")
|
||||
if ok {
|
||||
if m.IsEnabledIn(ctx.Event.GroupID) {
|
||||
ctx.Send(message.Text("已启用!"))
|
||||
} else {
|
||||
m.Enable(ctx.Event.GroupID)
|
||||
ctx.Send(message.Text("添加成功!"))
|
||||
}
|
||||
} else {
|
||||
ctx.Send(message.Text("找不到该服务!"))
|
||||
}
|
||||
})
|
||||
en.OnCommand("关闭粉丝日报", zero.AdminPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
m, ok := control.Lookup("fansdaily")
|
||||
if ok {
|
||||
if m.IsEnabledIn(ctx.Event.GroupID) {
|
||||
m.Disable(ctx.Event.GroupID)
|
||||
ctx.Send(message.Text("关闭成功!"))
|
||||
} else {
|
||||
ctx.Send(message.Text("未启用!"))
|
||||
}
|
||||
} else {
|
||||
ctx.Send(message.Text("找不到该服务!"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 定时任务每天晚上最后2分钟执行一次
|
||||
func fansDaily() {
|
||||
_, err := process.CronTab.AddFunc("58 23 * * *", func() { sendNotice() })
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取数据拼接消息链并发送
|
||||
func getMsg() message.MessageSegment {
|
||||
var (
|
||||
diana = fansapi("672328094")
|
||||
ava = fansapi("672346917")
|
||||
eileen = fansapi("672342685")
|
||||
bella = fansapi("672353429")
|
||||
carol = fansapi("351609538")
|
||||
)
|
||||
return message.Text(
|
||||
time.Now().Format("2006-01-02"), " Asoul全团粉丝日报如下", "\n\n",
|
||||
"uid: ", diana.Mid, "\n",
|
||||
"名字: ", diana.Uname, "\n",
|
||||
"当前粉丝数: ", diana.Follower, "\n",
|
||||
"今日涨粉数: ", diana.Rise, "\n",
|
||||
"视频投稿数: ", diana.Video, "\n",
|
||||
"直播间id: ", diana.Roomid, "\n",
|
||||
"舰队: ", diana.GuardNum, "\n",
|
||||
"直播总排名: ", diana.AreaRank, "\n",
|
||||
"数据来源: ", "https://vtbs.moe/detail/", "672328094", "\n\n",
|
||||
|
||||
"uid: ", ava.Mid, "\n",
|
||||
"名字: ", ava.Uname, "\n",
|
||||
"当前粉丝数: ", ava.Follower, "\n",
|
||||
"今日涨粉数: ", ava.Rise, "\n",
|
||||
"视频投稿数: ", ava.Video, "\n",
|
||||
"直播间id: ", ava.Roomid, "\n",
|
||||
"舰队: ", ava.GuardNum, "\n",
|
||||
"直播总排名: ", ava.AreaRank, "\n",
|
||||
"数据来源: ", "https://vtbs.moe/detail/", "672346917", "\n\n",
|
||||
|
||||
"uid: ", eileen.Mid, "\n",
|
||||
"名字: ", eileen.Uname, "\n",
|
||||
"当前粉丝数: ", eileen.Follower, "\n",
|
||||
"今日涨粉数: ", eileen.Rise, "\n",
|
||||
"视频投稿数: ", eileen.Video, "\n",
|
||||
"直播间id: ", eileen.Roomid, "\n",
|
||||
"舰队: ", eileen.GuardNum, "\n",
|
||||
"直播总排名: ", eileen.AreaRank, "\n",
|
||||
"数据来源: ", "https://vtbs.moe/detail/", "672342685", "\n\n",
|
||||
|
||||
"uid: ", bella.Mid, "\n",
|
||||
"名字: ", bella.Uname, "\n",
|
||||
"当前粉丝数: ", bella.Follower, "\n",
|
||||
"今日涨粉数: ", bella.Rise, "\n",
|
||||
"视频投稿数: ", bella.Video, "\n",
|
||||
"直播间id: ", bella.Roomid, "\n",
|
||||
"舰队: ", bella.GuardNum, "\n",
|
||||
"直播总排名: ", bella.AreaRank, "\n",
|
||||
"数据来源: ", "https://vtbs.moe/detail/", "672353429", "\n\n",
|
||||
|
||||
"uid: ", carol.Mid, "\n",
|
||||
"名字: ", carol.Uname, "\n",
|
||||
"当前粉丝数: ", carol.Follower, "\n",
|
||||
"今日涨粉数: ", carol.Rise, "\n",
|
||||
"视频投稿数: ", carol.Video, "\n",
|
||||
"直播间id: ", carol.Roomid, "\n",
|
||||
"舰队: ", carol.GuardNum, "\n",
|
||||
"直播总排名: ", carol.AreaRank, "\n",
|
||||
"数据来源: ", "https://vtbs.moe/detail/", "351609538",
|
||||
)
|
||||
}
|
||||
|
||||
// 获取数据拼接消息链并发送
|
||||
func sendNotice() {
|
||||
m, ok := control.Lookup("fansdaily")
|
||||
if ok {
|
||||
msg := getMsg()
|
||||
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
|
||||
for _, g := range ctx.GetGroupList().Array() {
|
||||
grp := g.Get("group_id").Int()
|
||||
if m.IsEnabledIn(grp) {
|
||||
ctx.SendGroupMessage(grp, msg)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 请求api
|
||||
func fansapi(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
|
||||
}
|
||||
65
plugin/bilibili/info.go
Normal file
65
plugin/bilibili/info.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Package bilibili 查询b站用户信息
|
||||
package bilibili
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
)
|
||||
|
||||
var engine = control.Register("bilibili", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "bilibili\n" +
|
||||
"- >vup info [名字 | uid]\n" +
|
||||
"- >user info [名字 | uid]",
|
||||
})
|
||||
|
||||
// 查成分的
|
||||
func init() {
|
||||
engine.OnRegex(`^>(?:user|vup)\s?info\s?(.{1,25})$`).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
keyword := ctx.State["regex_matched"].([]string)[1]
|
||||
rest, err := uid(keyword)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
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(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")
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
data := string(body)
|
||||
ctx.SendChain(message.Text(
|
||||
"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"),
|
||||
))
|
||||
})
|
||||
}
|
||||
59
plugin/bilibili/live_info.go
Normal file
59
plugin/bilibili/live_info.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package bilibili
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
// 查vup粉丝数据
|
||||
func init() {
|
||||
engine.OnRegex(`^>vup info\s?(.{1,25})$`).SetBlock(true).
|
||||
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").String()
|
||||
// 获取详情
|
||||
json := fansapi(id)
|
||||
ctx.SendChain(message.Text(
|
||||
"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)
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user