Skip to content

Commit 0887d9b

Browse files
committed
🎨 修改传参方式
1 parent c051f2f commit 0887d9b

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

plugin/bilibili/bilibili_parse.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
searchDynamicRe = regexp.MustCompile(searchDynamic)
4040
searchArticleRe = regexp.MustCompile(searchArticle)
4141
searchLiveRoomRe = regexp.MustCompile(searchLiveRoom)
42+
cachePath string
4243
)
4344

4445
// 插件主体
@@ -48,14 +49,13 @@ func init() {
4849
Brief: "b站链接解析",
4950
Help: "例:- t.bilibili.com/642277677329285174\n- bilibili.com/read/cv17134450\n- bilibili.com/video/BV13B4y1x7pS\n- live.bilibili.com/22603245 ",
5051
})
51-
cachePath := en.DataFolder() + "cache/"
52+
cachePath = en.DataFolder() + "cache/"
5253
_ = os.RemoveAll(cachePath)
5354
_ = os.MkdirAll(cachePath, 0755)
5455
en.OnRegex(`((b23|acg).tv|bili2233.cn)\\?/[0-9a-zA-Z]+`).SetBlock(true).Limit(limit.LimitByGroup).
5556
Handle(func(ctx *zero.Ctx) {
5657
u := ctx.State["regex_matched"].([]string)[0]
5758
u = strings.ReplaceAll(u, "\\", "")
58-
ctx.State["cache_path"] = cachePath
5959
realurl, err := bz.GetRealURL("https://" + u)
6060
if err != nil {
6161
ctx.SendChain(message.Text("ERROR: ", err))
@@ -105,22 +105,10 @@ func init() {
105105
}
106106
ctx.SendChain(message.Text("已", option, "视频总结"))
107107
})
108-
en.OnRegex(searchVideo, func(ctx *zero.Ctx) bool {
109-
ctx.State["cache_path"] = cachePath
110-
return true
111-
}).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleVideo)
112-
en.OnRegex(searchDynamic, func(ctx *zero.Ctx) bool {
113-
ctx.State["cache_path"] = cachePath
114-
return true
115-
}).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic)
116-
en.OnRegex(searchArticle, func(ctx *zero.Ctx) bool {
117-
ctx.State["cache_path"] = cachePath
118-
return true
119-
}).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle)
120-
en.OnRegex(searchLiveRoom, func(ctx *zero.Ctx) bool {
121-
ctx.State["cache_path"] = cachePath
122-
return true
123-
}).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleLive)
108+
en.OnRegex(searchVideo).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleVideo)
109+
en.OnRegex(searchDynamic).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic)
110+
en.OnRegex(searchArticle).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle)
111+
en.OnRegex(searchLiveRoom).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleLive)
124112
}
125113

126114
func handleVideo(ctx *zero.Ctx) {
@@ -148,7 +136,6 @@ func handleVideo(ctx *zero.Ctx) {
148136
}
149137
}
150138
ctx.SendChain(msg...)
151-
cachePath := ctx.State["cache_path"].(string)
152139
downLoadMsg, err := getVideoDownload(cfg, card, cachePath)
153140
if err != nil {
154141
ctx.SendChain(message.Text("ERROR: ", err))
@@ -256,7 +243,7 @@ func getVideoDownload(cookiecfg *bz.CookieConfig, card bz.Card, cachePath string
256243
cmd.Stderr = &stderr
257244
err = cmd.Run()
258245
if err != nil {
259-
err = errors.Errorf("未配置ffmpeg,%s", stderr.String())
246+
err = errors.Errorf("未配置ffmpeg,%v", stderr)
260247
return
261248
}
262249
msg = append(msg, message.Video("file:///"+file.BOTPATH+"/"+videoFile))

0 commit comments

Comments
 (0)