mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✨ lolicon add custom rand api
This commit is contained in:
parent
ec3b6ec5fa
commit
9034fedbd0
@ -612,6 +612,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"`
|
||||
|
||||
- [x] 来份萝莉
|
||||
- [x] 设置随机图片地址[http...]
|
||||
|
||||
</details>
|
||||
<details>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
package lolicon
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -24,17 +25,29 @@ const (
|
||||
|
||||
var (
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user