22package lolicon
33
44import (
5+ "encoding/base64"
56 "strings"
67 "time"
78
@@ -23,18 +24,30 @@ const (
2324)
2425
2526var (
26- queue = make (chan string , capacity )
27+ queue = make (chan string , capacity )
28+ custapi = ""
2729)
2830
2931func 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