mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
fix:修改vtb语录存为本地路径,去掉bilibilipush缓存 (#130)
* fix:修改vtb语录存为本地路径,去掉bilibilipush缓存 * fix:bilibiliparse添加up和粉丝数,修改bilibilipush的时间 * Update bilibili_parse.go Co-authored-by: Guohuiyuan <haibaraguo@yeahka.com> Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
This commit is contained in:
parent
9986c57727
commit
861b0b6cef
@ -279,7 +279,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
|
||||
- **网易云音乐热评** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wangyiyun"`
|
||||
- [x] 来份网易云热评
|
||||
- **b站视频链接解析** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili_parse"`
|
||||
- [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA
|
||||
- [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF
|
||||
- **煎蛋网无聊图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_jandan"`
|
||||
- [x] 来份屌图
|
||||
- [x] 更新屌图
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
package bilibiliparse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@ -14,8 +15,8 @@ import (
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
)
|
||||
|
||||
var (
|
||||
bilibiliRe = "https://www.bilibili.com/video/av[0-9]+|https://www.bilibili.com/video/BV[0-9a-zA-Z]+|https://b23.tv/[0-9a-zA-Z]+"
|
||||
const (
|
||||
bilibiliRe = "https://www.bilibili.com/video/av[0-9]+|https://www.bilibili.com/video/BV[0-9a-zA-Z]+|https://b23.tv/[0-9a-zA-Z]+|https://www.bilibili.com/video/bv[0-9a-zA-Z]+"
|
||||
validRe = "https://www.bilibili.com/video/(BV[0-9a-zA-Z]+)"
|
||||
)
|
||||
|
||||
@ -23,7 +24,7 @@ func init() {
|
||||
engine := control.Register("bilibiliparse", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "b站视频链接解析\n" +
|
||||
"- https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA",
|
||||
"- https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF",
|
||||
})
|
||||
|
||||
engine.OnRegex(bilibiliRe).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
@ -48,6 +49,11 @@ func parseURL(bilibiliURL string) (m message.Message) {
|
||||
bv := re.FindStringSubmatch(videoURL)[1]
|
||||
title := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/h1/span/text()").Data
|
||||
m = append(m, message.Text(title+"\n"))
|
||||
upName := strings.TrimSpace(htmlquery.FindOne(doc, "//*[@id='v_upinfo']/div[2]/div[1]/a[1]/text()").Data)
|
||||
fmt.Println(upName)
|
||||
fanNumber := htmlquery.InnerText(htmlquery.FindOne(doc, "//i[@class='van-icon-general_addto_s']").NextSibling.NextSibling)
|
||||
fmt.Println(fanNumber)
|
||||
m = append(m, message.Text("up:"+upName+",粉丝:"+fanNumber+"\n"))
|
||||
view := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/div/span[@class='view']/text()").Data
|
||||
dm := htmlquery.FindOne(doc, "//*[@id='viewbox_report']/div/span[@class='dm']/text()").Data
|
||||
m = append(m, message.Text(view+dm+"\n"))
|
||||
@ -57,10 +63,10 @@ func parseURL(bilibiliURL string) (m message.Message) {
|
||||
m = append(m, message.Image(image))
|
||||
like := htmlquery.FindOne(doc, "//*[@id='arc_toolbar_report']/div[1]/span[@class='like']/text()").Data
|
||||
coin := htmlquery.FindOne(doc, "//*[@id='arc_toolbar_report']/div[1]/span[@class='coin']/text()").Data
|
||||
m = append(m, message.Text("\n点赞:", strings.TrimSpace(like)+"投币:", strings.TrimSpace(coin)+"\n"))
|
||||
m = append(m, message.Text("\n点赞:", strings.TrimSpace(like)+",投币:", strings.TrimSpace(coin)+"\n"))
|
||||
collect := htmlquery.FindOne(doc, "//*[@id='arc_toolbar_report']/div[1]/span[@class='collect']/text()").Data
|
||||
share := htmlquery.FindOne(doc, "//*[@id='arc_toolbar_report']/div[1]/span[@class='share']/text()").Data
|
||||
m = append(m, message.Text("收藏:", strings.TrimSpace(collect)+"分享:", strings.TrimSpace(share)+"\n"))
|
||||
m = append(m, message.Text("收藏:", strings.TrimSpace(collect)+",分享:", strings.TrimSpace(share)+"\n"))
|
||||
m = append(m, message.Text(bv))
|
||||
return
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -75,14 +74,8 @@ func init() {
|
||||
// 加载数据库
|
||||
go func() {
|
||||
dbpath := en.DataFolder()
|
||||
cachePath := dbpath + "cache/"
|
||||
dbfile := dbpath + "push.db"
|
||||
defer order.DoneOnExit()()
|
||||
_ = os.RemoveAll(en.DataFolder() + "cache")
|
||||
err := os.MkdirAll(cachePath, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bdb = initialize(dbfile)
|
||||
log.Println("[bilibilipush]加载bilibilipush数据库")
|
||||
}()
|
||||
@ -388,7 +381,7 @@ func sendDynamic() {
|
||||
msg = append(msg, message.Text(cContent+"\n"))
|
||||
case 8:
|
||||
cName := gjson.Get(cOrigin, "owner.name").String()
|
||||
cTime := time.Unix(gjson.Get(cOrigin, "ctime").Int(), 0).Format("2006-01-02 15:04:05")
|
||||
cTime := time.Unix(gjson.Get(cOrigin, "pubdate").Int(), 0).Format("2006-01-02 15:04:05")
|
||||
msg = append(msg, message.Text(cName+"在"+cTime+typeMsg[cOrigType]+"\n"))
|
||||
cTitle := gjson.Get(cOrigin, "title").String()
|
||||
msg = append(msg, message.Text(cTitle))
|
||||
|
||||
@ -2,7 +2,12 @@
|
||||
package vtbquotation
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -24,6 +29,11 @@ import (
|
||||
)
|
||||
|
||||
const regStr = ".*/(.*)"
|
||||
const recordRe = "(\\.mp3|\\.wav|\\.wma|\\.mpa|\\.ram|\\.ra|\\.aac|\\.aif|\\.m4a|\\.tsa)"
|
||||
|
||||
var (
|
||||
re = regexp.MustCompile(recordRe)
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("vtbquotation", order.AcquirePrio(), &control.Options{
|
||||
@ -32,8 +42,13 @@ func init() {
|
||||
PublicDataFolder: "VtbQuotation",
|
||||
})
|
||||
dbfile := engine.DataFolder() + "vtb.db"
|
||||
storePath := engine.DataFolder() + "store/"
|
||||
go func() {
|
||||
defer order.DoneOnExit()()
|
||||
err := os.MkdirAll(storePath, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, _ = file.GetLazyData(dbfile, false, false)
|
||||
}()
|
||||
engine.OnFullMatch("vtb语录").SetBlock(true).
|
||||
@ -164,7 +179,19 @@ func init() {
|
||||
// log.Println(recordUrl)
|
||||
}
|
||||
ctx.SendChain(message.Reply(e.MessageID), message.Text("请欣赏《"+tc.ThirdCategoryName+"》"))
|
||||
ctx.SendChain(message.Record(recURL))
|
||||
|
||||
if !re.MatchString(recURL) {
|
||||
log.Errorln("[vtb]:文件格式不匹配")
|
||||
return
|
||||
}
|
||||
format := re.FindStringSubmatch(recURL)[1]
|
||||
recordFile := storePath + fmt.Sprintf("%d-%d-%d", firstIndex, secondIndex, thirdIndex) + format
|
||||
if file.IsExist(recordFile) {
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
initRecord(recordFile, recURL)
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -194,7 +221,18 @@ func init() {
|
||||
recURL = strings.ReplaceAll(recURL, "+", "%20")
|
||||
}
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请欣赏"+fc.FirstCategoryName+"的《"+tc.ThirdCategoryName+"》"))
|
||||
ctx.SendChain(message.Record(recURL))
|
||||
if !re.MatchString(recURL) {
|
||||
log.Errorln("[vtb]:文件格式不匹配")
|
||||
return
|
||||
}
|
||||
format := re.FindStringSubmatch(recURL)[1]
|
||||
recordFile := storePath + fmt.Sprintf("%d-%d-%d", fc.FirstCategoryIndex, tc.SecondCategoryIndex, tc.ThirdCategoryIndex) + format
|
||||
if file.IsExist(recordFile) {
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
initRecord(recordFile, recURL)
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
}
|
||||
db.Close()
|
||||
})
|
||||
@ -214,3 +252,34 @@ func init() {
|
||||
ctx.Send("vtb数据库已更新")
|
||||
})
|
||||
}
|
||||
|
||||
func initRecord(recordFile, recordURL string) {
|
||||
if file.IsNotExist(recordFile) {
|
||||
transport := http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
MaxVersion: tls.VersionTLS12,
|
||||
},
|
||||
}
|
||||
client := &http.Client{
|
||||
Transport: &transport,
|
||||
}
|
||||
req, _ := http.NewRequest("GET", recordURL, nil)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
return
|
||||
}
|
||||
err = os.WriteFile(recordFile, data, 0666)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user