mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +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"`
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"`
|
||||||
|
|
||||||
- [x] 来份萝莉
|
- [x] 来份萝莉
|
||||||
|
- [x] 设置随机图片地址[http...]
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
package lolicon
|
package lolicon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -23,18 +24,30 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
queue = make(chan string, capacity)
|
queue = make(chan string, capacity)
|
||||||
|
custapi = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
control.Register("lolicon", &control.Options{
|
en := control.Register("lolicon", &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "lolicon\n" +
|
Help: "lolicon\n" +
|
||||||
"- 来份萝莉",
|
"- 来份萝莉\n" +
|
||||||
}).ApplySingle(ctxext.DefaultSingle).OnFullMatch("来份萝莉").SetBlock(true).
|
"- 设置随机图片地址[http...]",
|
||||||
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
en.OnFullMatch("来份萝莉").SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {
|
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)
|
data, err := web.GetData(api)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
@ -67,6 +80,7 @@ func init() {
|
|||||||
case img := <-queue:
|
case img := <-queue:
|
||||||
id := ctx.SendChain(message.Image(img))
|
id := ctx.SendChain(message.Image(img))
|
||||||
if id.ID() == 0 {
|
if id.ID() == 0 {
|
||||||
|
process.SleepAbout1sTo2s()
|
||||||
id = ctx.SendChain(message.Image(img).Add("cache", "0"))
|
id = ctx.SendChain(message.Image(img).Add("cache", "0"))
|
||||||
if id.ID() == 0 {
|
if id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR:图片发送失败,可能被风控了~"))
|
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