mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
add control for saucenao & bilibili_parse (#839)
* add control for saucenao&bilibili_parse * not only group * update control * reuse variables --------- Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
This commit is contained in:
parent
0e3c025b80
commit
3225a2d6c7
@ -18,6 +18,11 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
enableHex = 0x10
|
||||||
|
unableHex = 0x7fffffff_fffffffd
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
limit = ctxext.NewLimiterManager(time.Second*10, 1)
|
limit = ctxext.NewLimiterManager(time.Second*10, 1)
|
||||||
searchVideo = `bilibili.com\\?/video\\?/(?:av(\d+)|([bB][vV][0-9a-zA-Z]+))`
|
searchVideo = `bilibili.com\\?/video\\?/(?:av(\d+)|([bB][vV][0-9a-zA-Z]+))`
|
||||||
@ -61,6 +66,35 @@ func init() {
|
|||||||
handleLive(ctx)
|
handleLive(ctx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
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 |= enableHex
|
||||||
|
case "关闭", "关掉", "禁用":
|
||||||
|
data &= unableHex
|
||||||
|
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(searchVideo).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleVideo)
|
||||||
en.OnRegex(searchDynamic).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic)
|
en.OnRegex(searchDynamic).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleDynamic)
|
||||||
en.OnRegex(searchArticle).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle)
|
en.OnRegex(searchArticle).SetBlock(true).Limit(limit.LimitByGroup).Handle(handleArticle)
|
||||||
@ -82,13 +116,15 @@ func handleVideo(ctx *zero.Ctx) {
|
|||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
summaryMsg, err := getVideoSummary(cfg, card)
|
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||||
if err != nil {
|
if ok && c.GetData(ctx.Event.GroupID)&enableHex == enableHex {
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
summaryMsg, err := getVideoSummary(card)
|
||||||
ctx.SendChain(msg...)
|
if err != nil {
|
||||||
return
|
msg = append(msg, message.Text("ERROR: ", err))
|
||||||
|
} else {
|
||||||
|
msg = append(msg, summaryMsg...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msg = append(msg, summaryMsg...)
|
|
||||||
ctx.SendChain(msg...)
|
ctx.SendChain(msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,11 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/img/pool"
|
"github.com/FloatTech/zbputils/img/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
enableHex = 0x10
|
||||||
|
unableHex = 0x7fffffff_fffffffd
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
saucenaocli *gophersauce.Client
|
saucenaocli *gophersauce.Client
|
||||||
)
|
)
|
||||||
@ -111,10 +116,15 @@ func init() { // 插件主体
|
|||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
// 开始搜索图片
|
// 开始搜索图片
|
||||||
pics, ok := ctx.State["image_url"].([]string)
|
pics, ok := ctx.State["image_url"].([]string)
|
||||||
|
showPic := false
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.SendChain(message.Text("ERROR: 未获取到图片链接"))
|
ctx.SendChain(message.Text("ERROR: 未获取到图片链接"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||||
|
if ok && c.GetData(ctx.Event.GroupID)&enableHex == enableHex {
|
||||||
|
showPic = true
|
||||||
|
}
|
||||||
ctx.SendChain(message.Text("少女祈祷中..."))
|
ctx.SendChain(message.Text("少女祈祷中..."))
|
||||||
for _, pic := range pics {
|
for _, pic := range pics {
|
||||||
if saucenaocli != nil {
|
if saucenaocli != nil {
|
||||||
@ -142,15 +152,17 @@ func init() { // 插件主体
|
|||||||
} else {
|
} else {
|
||||||
msg = append(msg, message.Text("也许是这个?"))
|
msg = append(msg, message.Text("也许是这个?"))
|
||||||
}
|
}
|
||||||
if err == nil {
|
if showPic {
|
||||||
_ = resp.Body.Close()
|
if err == nil {
|
||||||
if resp.StatusCode == http.StatusOK {
|
_ = resp.Body.Close()
|
||||||
msg = append(msg, message.Image(result.Header.Thumbnail))
|
if resp.StatusCode == http.StatusOK {
|
||||||
|
msg = append(msg, message.Image(result.Header.Thumbnail))
|
||||||
|
} else {
|
||||||
|
msg = append(msg, message.Image(pic))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg = append(msg, message.Image(pic))
|
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)))
|
msg = append(msg, message.Text("\n图源: ", result.Header.IndexName, binary.BytesToString(b)))
|
||||||
ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, msg...)})
|
ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, msg...)})
|
||||||
@ -170,17 +182,19 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
msg := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text("ascii2d搜图结果"))}
|
msg := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text("ascii2d搜图结果"))}
|
||||||
for i := 0; i < len(result) && i < 5; i++ {
|
for i := 0; i < len(result) && i < 5; i++ {
|
||||||
msg = append(msg, ctxext.FakeSenderForwardNode(ctx,
|
var resultMsgs message.Message
|
||||||
message.Image(result[i].Thumb),
|
if showPic {
|
||||||
message.Text(fmt.Sprintf(
|
resultMsgs = append(resultMsgs, message.Image(result[i].Thumb))
|
||||||
"标题: %s\n图源: %s\n画师: %s\n画师链接: %s\n图片链接: %s",
|
}
|
||||||
result[i].Name,
|
resultMsgs = append(resultMsgs, message.Text(fmt.Sprintf(
|
||||||
result[i].Type,
|
"标题: %s\n图源: %s\n画师: %s\n画师链接: %s\n图片链接: %s",
|
||||||
result[i].AuthNm,
|
result[i].Name,
|
||||||
result[i].Author,
|
result[i].Type,
|
||||||
result[i].Link,
|
result[i].AuthNm,
|
||||||
))),
|
result[i].Author,
|
||||||
)
|
result[i].Link,
|
||||||
|
)))
|
||||||
|
msg = append(msg, ctxext.FakeSenderForwardNode(ctx, resultMsgs...))
|
||||||
}
|
}
|
||||||
if id := ctx.Send(msg).ID(); id == 0 {
|
if id := ctx.Send(msg).ID(); id == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||||
@ -205,4 +219,33 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("成功!"))
|
ctx.SendChain(message.Text("成功!"))
|
||||||
})
|
})
|
||||||
|
engine.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 |= enableHex
|
||||||
|
case "关闭", "关掉", "禁用":
|
||||||
|
data &= unableHex
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := c.SetData(gid, data)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("出错啦: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text("已", option, "搜图显示图片"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user