Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add control for saucenao & bilibili_parse #839

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 37 additions & 5 deletions plugin/bilibili/bilibili_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,35 @@ func init() {
handleLive(ctx)
}
})
en.OnRegex(`^(.*)视频总结$`, zero.AdminPermission).SetBlock(true).
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
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 {
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
data := c.GetData(ctx.Event.GroupID)
switch option {
case "开启", "打开", "启用":
data |= 0x10
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
case "关闭", "关掉", "禁用":
data &= 0x7fffffff_fffffffd
default:
return
}
err := c.SetData(gid, data)
if err == nil {
ctx.SendChain(message.Text("已", option))
return
}
ctx.SendChain(message.Text("出错啦: ", err))
return
}
ctx.SendChain(message.Text("找不到服务!"))
})
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)
Expand All @@ -76,12 +105,15 @@ func handleVideo(ctx *zero.Ctx) {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
summaryMsg, err := getVideoSummary(card)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if ok && c.GetData(ctx.Event.GroupID)&0x10 == 0x10 {
summaryMsg, err := getVideoSummary(card)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
msg = append(msg, summaryMsg...)
}
msg = append(msg, summaryMsg...)
ctx.SendChain(msg...)
}

Expand Down
83 changes: 66 additions & 17 deletions plugin/saucenao/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
// 开始搜索图片
pics, ok := ctx.State["image_url"].([]string)
showPic := false
if !ok {
ctx.SendChain(message.Text("ERROR: 未获取到图片链接"))
return
}
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if ok && c.GetData(ctx.Event.GroupID)&0x10 == 0x10 {
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
showPic = true
}
ctx.SendChain(message.Text("少女祈祷中..."))
for _, pic := range pics {
if saucenaocli != nil {
Expand Down Expand Up @@ -142,15 +147,17 @@ func init() { // 插件主体
} else {
msg = append(msg, message.Text("也许是这个?"))
}
if err == nil {
_ = resp.Body.Close()
if resp.StatusCode == http.StatusOK {
msg = append(msg, message.Image(result.Header.Thumbnail))
if showPic {
if err == nil {
_ = resp.Body.Close()
if resp.StatusCode == http.StatusOK {
msg = append(msg, message.Image(result.Header.Thumbnail))
} else {
msg = append(msg, message.Image(pic))
}
} else {
msg = append(msg, message.Image(pic))
}
} else {
msg = append(msg, message.Image(pic))
}
msg = append(msg, message.Text("\n图源: ", result.Header.IndexName, binary.BytesToString(b)))
ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, msg...)})
Expand All @@ -170,17 +177,30 @@ func init() { // 插件主体
}
msg := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text("ascii2d搜图结果"))}
for i := 0; i < len(result) && i < 5; i++ {
msg = append(msg, ctxext.FakeSenderForwardNode(ctx,
message.Image(result[i].Thumb),
message.Text(fmt.Sprintf(
"标题: %s\n图源: %s\n画师: %s\n画师链接: %s\n图片链接: %s",
result[i].Name,
result[i].Type,
result[i].AuthNm,
result[i].Author,
result[i].Link,
))),
)
if showPic {
msg = append(msg, ctxext.FakeSenderForwardNode(ctx,
message.Image(result[i].Thumb),
message.Text(fmt.Sprintf(
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
"标题: %s\n图源: %s\n画师: %s\n画师链接: %s\n图片链接: %s",
result[i].Name,
result[i].Type,
result[i].AuthNm,
result[i].Author,
result[i].Link,
))),
)
} else {
msg = append(msg, ctxext.FakeSenderForwardNode(ctx,
message.Text(fmt.Sprintf(
"标题: %s\n图源: %s\n画师: %s\n画师链接: %s\n图片链接: %s",
result[i].Name,
result[i].Type,
result[i].AuthNm,
result[i].Author,
result[i].Link,
))),
)
}
}
if id := ctx.Send(msg).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
Expand All @@ -205,4 +225,33 @@ func init() { // 插件主体
}
ctx.SendChain(message.Text("成功!"))
})
engine.OnRegex(`^(.*)搜图显示图片$`, zero.AdminPermission).SetBlock(true).
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
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 {
shudorcl marked this conversation as resolved.
Show resolved Hide resolved
data := c.GetData(ctx.Event.GroupID)
switch option {
case "开启", "打开", "启用":
data |= 0x10
case "关闭", "关掉", "禁用":
data &= 0x7fffffff_fffffffd
default:
return
}
err := c.SetData(gid, data)
if err == nil {
ctx.SendChain(message.Text("已", option))
return
}
ctx.SendChain(message.Text("出错啦: ", err))
return
}
ctx.SendChain(message.Text("找不到服务!"))
})
}
Loading