2
2
package lolicon
3
3
4
4
import (
5
+ "encoding/base64"
5
6
"strings"
6
7
"time"
7
8
@@ -23,18 +24,30 @@ const (
23
24
)
24
25
25
26
var (
26
- queue = make (chan string , capacity )
27
+ queue = make (chan string , capacity )
28
+ custapi = ""
27
29
)
28
30
29
31
func init () {
30
- control .Register ("lolicon" , & control.Options {
32
+ en := control .Register ("lolicon" , & control.Options {
31
33
DisableOnDefault : false ,
32
34
Help : "lolicon\n " +
33
- "- 来份萝莉" ,
34
- }).ApplySingle (ctxext .DefaultSingle ).OnFullMatch ("来份萝莉" ).SetBlock (true ).
35
+ "- 来份萝莉\n " +
36
+ "- 设置随机图片地址[http...]" ,
37
+ }).ApplySingle (ctxext .DefaultSingle )
38
+ en .OnFullMatch ("来份萝莉" ).SetBlock (true ).
35
39
Handle (func (ctx * zero.Ctx ) {
36
40
go func () {
37
41
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
+ }
38
51
data , err := web .GetData (api )
39
52
if err != nil {
40
53
ctx .SendChain (message .Text ("ERROR:" , err ))
@@ -67,11 +80,21 @@ func init() {
67
80
case img := <- queue :
68
81
id := ctx .SendChain (message .Image (img ))
69
82
if id .ID () == 0 {
83
+ process .SleepAbout1sTo2s ()
70
84
id = ctx .SendChain (message .Image (img ).Add ("cache" , "0" ))
71
85
if id .ID () == 0 {
72
86
ctx .SendChain (message .Text ("ERROR:图片发送失败,可能被风控了~" ))
73
87
}
74
88
}
75
89
}
76
90
})
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
+ })
77
100
}
0 commit comments