Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] 更新屌图
Expand Down
16 changes: 11 additions & 5 deletions plugin_bilibili_parse/bilibili_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package bilibiliparse

import (
"fmt"
"regexp"
"strings"

Expand All @@ -14,16 +15,16 @@ 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]+)"
)

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) {
Expand All @@ -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"))
Expand All @@ -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
}
9 changes: 1 addition & 8 deletions plugin_bilibili_push/bilibili_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"time"

Expand Down Expand Up @@ -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数据库")
}()
Expand Down Expand Up @@ -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))
Expand Down
73 changes: 71 additions & 2 deletions plugin_vtb_quotation/vtb_quotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
package vtbquotation

import (
"crypto/tls"
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"strings"
Expand All @@ -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{
Expand All @@ -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).
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()
})
Expand All @@ -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)
}
}
}