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) {