From ac2d53352c3f4bca6285777d4299ce9c180483f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E6=80=9D=E6=BD=8B?= <55676105+shudorcl@users.noreply.github.com> Date: Wed, 3 Sep 2025 13:02:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(bilibiliparse):=20B=E7=AB=99=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=A7=A3=E6=9E=90=20=E8=A7=86=E9=A2=91=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=BC=80=E5=85=B3=20(#1196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add control for getVideoDownload * fix: typo --- plugin/bilibili/bilibili_parse.go | 53 +++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/plugin/bilibili/bilibili_parse.go b/plugin/bilibili/bilibili_parse.go index 189c6586..81dd03bd 100644 --- a/plugin/bilibili/bilibili_parse.go +++ b/plugin/bilibili/bilibili_parse.go @@ -24,8 +24,10 @@ import ( ) const ( - enableHex = 0x10 - unableHex = 0x7fffffff_fffffffd + enableVideoSummary = int64(0x10) + disableVideoSummary = ^enableVideoSummary + enableVideoDownload = int64(0x20) + disableVideoDownload = ^enableVideoDownload bilibiliparseReferer = "https://www.bilibili.com" ) @@ -92,9 +94,9 @@ func init() { data := c.GetData(ctx.Event.GroupID) switch option { case "开启", "打开", "启用": - data |= enableHex + data |= enableVideoSummary case "关闭", "关掉", "禁用": - data &= unableHex + data &= disableVideoSummary default: return } @@ -105,6 +107,35 @@ func init() { } ctx.SendChain(message.Text("已", option, "视频总结")) }) + en.OnRegex(`^(开启|打开|启用|关闭|关掉|禁用)视频上传$`, zero.AdminPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + if gid <= 0 { + // 个人用户设为负数 + gid = -ctx.Event.UserID + } + option := ctx.State["regex_matched"].([]string)[1] + c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) + if !ok { + ctx.SendChain(message.Text("找不到服务!")) + return + } + data := c.GetData(ctx.Event.GroupID) + switch option { + case "开启", "打开", "启用": + data |= enableVideoDownload + case "关闭", "关掉", "禁用": + data &= disableVideoDownload + default: + return + } + err := c.SetData(gid, data) + if err != nil { + ctx.SendChain(message.Text("出错啦: ", err)) + return + } + ctx.SendChain(message.Text("已", option, "视频上传")) + }) en.OnRegex(searchVideo).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleVideo) en.OnRegex(searchDynamic).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic) en.OnRegex(searchArticle).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle) @@ -127,7 +158,7 @@ func handleVideo(ctx *zero.Ctx) { return } c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) - if ok && c.GetData(ctx.Event.GroupID)&enableHex == enableHex { + if ok && c.GetData(ctx.Event.GroupID)&enableVideoSummary == enableVideoSummary { summaryMsg, err := getVideoSummary(cfg, card) if err != nil { msg = append(msg, message.Text("ERROR: ", err)) @@ -136,12 +167,14 @@ func handleVideo(ctx *zero.Ctx) { } } ctx.SendChain(msg...) - downLoadMsg, err := getVideoDownload(cfg, card, cachePath) - if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return + if ok && c.GetData(ctx.Event.GroupID)&enableVideoDownload == enableVideoDownload { + downLoadMsg, err := getVideoDownload(cfg, card, cachePath) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return + } + ctx.SendChain(downLoadMsg...) } - ctx.SendChain(downLoadMsg...) } func handleDynamic(ctx *zero.Ctx) {