Skip to content

Commit ac2d533

Browse files
authored
feat(bilibiliparse): B站视频解析 视频上传开关 (FloatTech#1196)
* add control for getVideoDownload * fix: typo
1 parent 35292a6 commit ac2d533

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

plugin/bilibili/bilibili_parse.go

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
)
2525

2626
const (
27-
enableHex = 0x10
28-
unableHex = 0x7fffffff_fffffffd
27+
enableVideoSummary = int64(0x10)
28+
disableVideoSummary = ^enableVideoSummary
29+
enableVideoDownload = int64(0x20)
30+
disableVideoDownload = ^enableVideoDownload
2931
bilibiliparseReferer = "https://www.bilibili.com"
3032
)
3133

@@ -92,9 +94,9 @@ func init() {
9294
data := c.GetData(ctx.Event.GroupID)
9395
switch option {
9496
case "开启", "打开", "启用":
95-
data |= enableHex
97+
data |= enableVideoSummary
9698
case "关闭", "关掉", "禁用":
97-
data &= unableHex
99+
data &= disableVideoSummary
98100
default:
99101
return
100102
}
@@ -105,6 +107,35 @@ func init() {
105107
}
106108
ctx.SendChain(message.Text("已", option, "视频总结"))
107109
})
110+
en.OnRegex(`^(开启|打开|启用|关闭|关掉|禁用)视频上传$`, zero.AdminPermission).SetBlock(true).
111+
Handle(func(ctx *zero.Ctx) {
112+
gid := ctx.Event.GroupID
113+
if gid <= 0 {
114+
// 个人用户设为负数
115+
gid = -ctx.Event.UserID
116+
}
117+
option := ctx.State["regex_matched"].([]string)[1]
118+
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
119+
if !ok {
120+
ctx.SendChain(message.Text("找不到服务!"))
121+
return
122+
}
123+
data := c.GetData(ctx.Event.GroupID)
124+
switch option {
125+
case "开启", "打开", "启用":
126+
data |= enableVideoDownload
127+
case "关闭", "关掉", "禁用":
128+
data &= disableVideoDownload
129+
default:
130+
return
131+
}
132+
err := c.SetData(gid, data)
133+
if err != nil {
134+
ctx.SendChain(message.Text("出错啦: ", err))
135+
return
136+
}
137+
ctx.SendChain(message.Text("已", option, "视频上传"))
138+
})
108139
en.OnRegex(searchVideo).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleVideo)
109140
en.OnRegex(searchDynamic).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic)
110141
en.OnRegex(searchArticle).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle)
@@ -127,7 +158,7 @@ func handleVideo(ctx *zero.Ctx) {
127158
return
128159
}
129160
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
130-
if ok && c.GetData(ctx.Event.GroupID)&enableHex == enableHex {
161+
if ok && c.GetData(ctx.Event.GroupID)&enableVideoSummary == enableVideoSummary {
131162
summaryMsg, err := getVideoSummary(cfg, card)
132163
if err != nil {
133164
msg = append(msg, message.Text("ERROR: ", err))
@@ -136,12 +167,14 @@ func handleVideo(ctx *zero.Ctx) {
136167
}
137168
}
138169
ctx.SendChain(msg...)
139-
downLoadMsg, err := getVideoDownload(cfg, card, cachePath)
140-
if err != nil {
141-
ctx.SendChain(message.Text("ERROR: ", err))
142-
return
170+
if ok && c.GetData(ctx.Event.GroupID)&enableVideoDownload == enableVideoDownload {
171+
downLoadMsg, err := getVideoDownload(cfg, card, cachePath)
172+
if err != nil {
173+
ctx.SendChain(message.Text("ERROR: ", err))
174+
return
175+
}
176+
ctx.SendChain(downLoadMsg...)
143177
}
144-
ctx.SendChain(downLoadMsg...)
145178
}
146179

147180
func handleDynamic(ctx *zero.Ctx) {

0 commit comments

Comments
 (0)