mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
Merge branch 'master' of https://github.com/FloatTech/ZeroBot-Plugin
This commit is contained in:
commit
fe8a677541
@ -3,7 +3,6 @@ package bilibiliparse
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -55,8 +54,8 @@ type owner struct {
|
|||||||
Data struct {
|
Data struct {
|
||||||
Card struct {
|
Card struct {
|
||||||
Fans int `json:"fans"`
|
Fans int `json:"fans"`
|
||||||
} `json:"data"`
|
} `json:"card"`
|
||||||
}
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -67,6 +66,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
reg = regexp.MustCompile(`https://www.bilibili.com/video/([0-9a-zA-Z]+)`)
|
reg = regexp.MustCompile(`https://www.bilibili.com/video/([0-9a-zA-Z]+)`)
|
||||||
|
stop = regexp.MustCompile(`\[CQ:forward,id=.*\]`)
|
||||||
limit = ctxext.NewLimiterManager(time.Second*10, 1)
|
limit = ctxext.NewLimiterManager(time.Second*10, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,6 +79,9 @@ func init() {
|
|||||||
})
|
})
|
||||||
en.OnRegex(`(av[0-9]+|BV[0-9a-zA-Z]{10}){1}`).SetBlock(true).Limit(limit.LimitByGroup).
|
en.OnRegex(`(av[0-9]+|BV[0-9a-zA-Z]{10}){1}`).SetBlock(true).Limit(limit.LimitByGroup).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
if stop.MatchString(ctx.Event.RawMessage) {
|
||||||
|
return
|
||||||
|
}
|
||||||
id := ctx.State["regex_matched"].([]string)[1]
|
id := ctx.State["regex_matched"].([]string)[1]
|
||||||
m, err := parse(id)
|
m, err := parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -105,12 +108,7 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id, err := cuturl(realurl)
|
m, err := parse(cuturl(realurl))
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m, err := parse(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
@ -142,9 +140,9 @@ func parse(id string) (m message.Message, err error) {
|
|||||||
if r.Data.Rights.IsCooperation == 1 {
|
if r.Data.Rights.IsCooperation == 1 {
|
||||||
for i := 0; i < len(r.Data.Staff); i++ {
|
for i := 0; i < len(r.Data.Staff); i++ {
|
||||||
if i != len(r.Data.Staff) {
|
if i != len(r.Data.Staff) {
|
||||||
m = append(m, message.Text(r.Data.Staff[i].Title, ":", r.Data.Staff[i].Name, ",粉丝:", r.Data.Staff[i].Follower, "\n"))
|
m = append(m, message.Text(r.Data.Staff[i].Title, ":", r.Data.Staff[i].Name, ",粉丝:", row(r.Data.Staff[i].Follower), "\n"))
|
||||||
} else {
|
} else {
|
||||||
m = append(m, message.Text(r.Data.Staff[i].Title, ":", r.Data.Staff[i].Name, ",粉丝:", r.Data.Staff[i].Follower))
|
m = append(m, message.Text(r.Data.Staff[i].Title, ":", r.Data.Staff[i].Name, ",粉丝:", row(r.Data.Staff[i].Follower)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -152,11 +150,11 @@ func parse(id string) (m message.Message, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
m = append(m, message.Text("\nUP主:", r.Data.Owner.Name, ",粉丝:", o.Data.Card.Fans, "\n"))
|
m = append(m, message.Text("UP主:", r.Data.Owner.Name, ",粉丝:", row(o.Data.Card.Fans), "\n"))
|
||||||
}
|
}
|
||||||
m = append(m, message.Text("播放:", r.Data.Stat.View, ",弹幕:", r.Data.Stat.Danmaku, "\n"),
|
m = append(m, message.Text("播放:", row(r.Data.Stat.View), ",弹幕:", row(r.Data.Stat.Danmaku), "\n"),
|
||||||
message.Image(r.Data.Pic),
|
message.Image(r.Data.Pic),
|
||||||
message.Text("\n点赞:", r.Data.Stat.Like, ",投币:", r.Data.Stat.Coin, "\n收藏:", r.Data.Stat.Favorite, ",分享:", r.Data.Stat.Share, "\n", origin, id))
|
message.Text("\n点赞:", row(r.Data.Stat.Like), ",投币:", row(r.Data.Stat.Coin), "\n收藏:", row(r.Data.Stat.Favorite), ",分享:", row(r.Data.Stat.Share), "\n", origin, id))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,13 +169,11 @@ func getrealurl(url string) (realurl string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cuturl 获取aid或者bvid
|
// cuturl 获取aid或者bvid
|
||||||
func cuturl(url string) (id string, err error) {
|
func cuturl(url string) (id string) {
|
||||||
if !reg.MatchString(url) {
|
if !reg.MatchString(url) {
|
||||||
err = errors.New("invalid video url")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id = reg.FindStringSubmatch(url)[1]
|
return reg.FindStringSubmatch(url)[1]
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getcard 获取个人信息
|
// getcard 获取个人信息
|
||||||
@ -189,3 +185,10 @@ func getcard(mid int) (o owner, err error) {
|
|||||||
err = json.Unmarshal(data, &o)
|
err = json.Unmarshal(data, &o)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func row(res int) string {
|
||||||
|
if res/10000 != 0 {
|
||||||
|
return strconv.FormatFloat(float64(res)/10000, 'f', 2, 64) + "万"
|
||||||
|
}
|
||||||
|
return strconv.Itoa(res)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user