From 5d490be15b0193b563627e272f4143c50f2bc7e3 Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 17 Jun 2021 19:57:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=92=A4=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- randimg/setu_geter.go | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/randimg/setu_geter.go b/randimg/setu_geter.go index e36a0889..45e783b2 100644 --- a/randimg/setu_geter.go +++ b/randimg/setu_geter.go @@ -8,17 +8,22 @@ import ( "os" "strconv" "strings" + "time" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" zero "github.com/wdvxdr1123/ZeroBot" ) var ( - RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" - CLASSIFY_RANDOM_API_URL string = "http://saki.fumiama.top:62002/dice?url=" + RANDOM_API_URL - BLOCK_REQUEST = false - CACHE_IMG_FILE = "/tmp/setugt" - CACHE_URI = "file:///" + CACHE_IMG_FILE + RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" + CLASSIFY_RANDOM_API_URL = "http://saki.fumiama.top:62002/dice?url=" + RANDOM_API_URL + VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" + BLOCK_REQUEST = false + CACHE_IMG_FILE = "/tmp/setugt" + CACHE_URI = "file:///" + CACHE_IMG_FILE + last_message_id int64 + last_dhash string + last_visit = 0 ) func init() { // 插件主体 @@ -36,9 +41,10 @@ func init() { // 插件主体 zero.OnFullMatch("随机图片").SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { if ctx.Event.GroupID > 0 { - if BLOCK_REQUEST { + if BLOCK_REQUEST && time.Now().Unix()-last_message_id < 30 { ctx.Send("请稍后再试哦") } else { + last_message_id = time.Now().Unix() BLOCK_REQUEST = true if CLASSIFY_RANDOM_API_URL != "" { resp, err := http.Get(CLASSIFY_RANDOM_API_URL) @@ -46,6 +52,7 @@ func init() { // 插件主体 ctx.Send(fmt.Sprintf("ERROR: %v", err)) } else { class, err1 := strconv.Atoi(resp.Header.Get("Class")) + dhash := resp.Header.Get("DHash") if err1 != nil { ctx.Send(fmt.Sprintf("ERROR: %v", err1)) } else { @@ -57,7 +64,6 @@ func init() { // 插件主体 f.Write(data) if class > 4 { ctx.Send("太涩啦,不发了!") - dhash := resp.Header.Get("DHash") if dhash != "" { b14, err3 := url.QueryUnescape(dhash) if err3 == nil { @@ -65,7 +71,8 @@ func init() { // 插件主体 } } } else { - ctx.Send(msgext.ImageNoCache(CACHE_URI)) + last_message_id = ctx.Send(msgext.ImageNoCache(CACHE_URI)) + last_dhash = dhash if class > 2 { ctx.Send("我好啦!") } @@ -80,4 +87,24 @@ func init() { // 插件主体 } return }) + zero.OnFullMatch("不许好").SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + if last_message_id != 0 { + ctx.DeleteMessage(last_message_id) + last_message_id = 0 + vote(5) + } + }) + zero.OnFullMatch("太涩了").SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + if last_message_id != 0 { + ctx.DeleteMessage(last_message_id) + last_message_id = 0 + vote(6) + } + }) +} + +func vote(class int) { + http.Get(fmt.Sprintf(VOTE_API_URL, last_dhash, class)) }