Skip to content

Commit 9034fed

Browse files
committed
✨ lolicon add custom rand api
1 parent ec3b6ec commit 9034fed

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ print("run[CQ:image,file="+j["img"]+"]")
612612
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon"`
613613

614614
- [x] 来份萝莉
615+
- [x] 设置随机图片地址[http...]
615616

616617
</details>
617618
<details>

plugin/lolicon/lolicon.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package lolicon
33

44
import (
5+
"encoding/base64"
56
"strings"
67
"time"
78

@@ -23,18 +24,30 @@ const (
2324
)
2425

2526
var (
26-
queue = make(chan string, capacity)
27+
queue = make(chan string, capacity)
28+
custapi = ""
2729
)
2830

2931
func init() {
30-
control.Register("lolicon", &control.Options{
32+
en := control.Register("lolicon", &control.Options{
3133
DisableOnDefault: false,
3234
Help: "lolicon\n" +
33-
"- 来份萝莉",
34-
}).ApplySingle(ctxext.DefaultSingle).OnFullMatch("来份萝莉").SetBlock(true).
35+
"- 来份萝莉\n" +
36+
"- 设置随机图片地址[http...]",
37+
}).ApplySingle(ctxext.DefaultSingle)
38+
en.OnFullMatch("来份萝莉").SetBlock(true).
3539
Handle(func(ctx *zero.Ctx) {
3640
go func() {
3741
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {
42+
if custapi != "" {
43+
data, err := web.GetData(custapi)
44+
if err != nil {
45+
ctx.SendChain(message.Text("ERROR:", err))
46+
continue
47+
}
48+
queue <- "base64://" + base64.StdEncoding.EncodeToString(data)
49+
continue
50+
}
3851
data, err := web.GetData(api)
3952
if err != nil {
4053
ctx.SendChain(message.Text("ERROR:", err))
@@ -67,11 +80,21 @@ func init() {
6780
case img := <-queue:
6881
id := ctx.SendChain(message.Image(img))
6982
if id.ID() == 0 {
83+
process.SleepAbout1sTo2s()
7084
id = ctx.SendChain(message.Image(img).Add("cache", "0"))
7185
if id.ID() == 0 {
7286
ctx.SendChain(message.Text("ERROR:图片发送失败,可能被风控了~"))
7387
}
7488
}
7589
}
7690
})
91+
en.OnPrefix("设置随机图片地址", zero.SuperUserPermission).SetBlock(true).
92+
Handle(func(ctx *zero.Ctx) {
93+
u := strings.TrimSpace(ctx.State["args"].(string))
94+
if !strings.HasPrefix(u, "http") {
95+
ctx.SendChain(message.Text("ERROR:url非法!"))
96+
return
97+
}
98+
custapi = u
99+
})
77100
}

0 commit comments

Comments
 (0)