lolicon add custom rand api

This commit is contained in:
源文雨 2022-04-22 09:23:31 +08:00
parent ec3b6ec5fa
commit 9034fedbd0
2 changed files with 28 additions and 4 deletions

View File

@ -612,6 +612,7 @@ print("run[CQ:image,file="+j["img"]+"]")
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"`
- [x] 来份萝莉
- [x] 设置随机图片地址[http...]
</details>
<details>

View File

@ -2,6 +2,7 @@
package lolicon
import (
"encoding/base64"
"strings"
"time"
@ -23,18 +24,30 @@ const (
)
var (
queue = make(chan string, capacity)
queue = make(chan string, capacity)
custapi = ""
)
func init() {
control.Register("lolicon", &control.Options{
en := control.Register("lolicon", &control.Options{
DisableOnDefault: false,
Help: "lolicon\n" +
"- 来份萝莉",
}).ApplySingle(ctxext.DefaultSingle).OnFullMatch("来份萝莉").SetBlock(true).
"- 来份萝莉\n" +
"- 设置随机图片地址[http...]",
}).ApplySingle(ctxext.DefaultSingle)
en.OnFullMatch("来份萝莉").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
go func() {
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {
if custapi != "" {
data, err := web.GetData(custapi)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
continue
}
queue <- "base64://" + base64.StdEncoding.EncodeToString(data)
continue
}
data, err := web.GetData(api)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
@ -67,6 +80,7 @@ func init() {
case img := <-queue:
id := ctx.SendChain(message.Image(img))
if id.ID() == 0 {
process.SleepAbout1sTo2s()
id = ctx.SendChain(message.Image(img).Add("cache", "0"))
if id.ID() == 0 {
ctx.SendChain(message.Text("ERROR:图片发送失败,可能被风控了~"))
@ -74,4 +88,13 @@ func init() {
}
}
})
en.OnPrefix("设置随机图片地址", zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
u := strings.TrimSpace(ctx.State["args"].(string))
if !strings.HasPrefix(u, "http") {
ctx.SendChain(message.Text("ERROR:url非法!"))
return
}
custapi = u
})
}