From 48632e25b83cf5f83d2daa51e5620f3aea0494a3 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sat, 19 Jun 2021 14:37:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E5=85=83=E5=9B=BE=E7=89=87=E8=AF=84=E4=BB=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + api/classify/classify.go | 114 +++++++++++++++++++++++++++++++ api/context/pic.go | 58 ++++++++++++++++ go.mod | 2 +- go.sum | 4 +- picsearcher/pic_searcher.go | 55 +-------------- randimg/setu_geter.go | 129 ++++++++++-------------------------- 7 files changed, 215 insertions(+), 149 deletions(-) create mode 100644 api/classify/classify.go create mode 100644 api/context/pic.go diff --git a/README.md b/README.md index 047ce6bf..c9b9d49f 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,10 @@ - [x] 搜图[P站图片ID] - 简易随机图片(调用url) `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg"` - [x] 随机图片 + - [x] 直接随机(无r18检测,后果自负) - [x] 设置随机图片网址[url] - [x] 太涩了(撤回最近发的图) + - [x] 评价图片:发送一张图片进行评分 - 点歌 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music"` - [x] 点歌[xxx] - [x] 网易点歌[xxx] diff --git a/api/classify/classify.go b/api/classify/classify.go new file mode 100644 index 00000000..619283be --- /dev/null +++ b/api/classify/classify.go @@ -0,0 +1,114 @@ +package classify + +import ( + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "strconv" + + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" + "github.com/tidwall/gjson" + zero "github.com/wdvxdr1123/ZeroBot" +) + +var ( + BLOCK_REQUEST_CLASS = false + CACHE_IMG_FILE = "/tmp/setugt" + CACHE_URI = "file:///" + CACHE_IMG_FILE + VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" + CLASSIFY_HEAD = "http://saki.fumiama.top:62002/dice?url=" + msgofgrp = make(map[int64]int64) + dhashofmsg = make(map[int64]string) +) + +func Classify(ctx *zero.Ctx, targeturl string, noimg bool) { + if BLOCK_REQUEST_CLASS { + ctx.Send("请稍后再试哦") + } else { + BLOCK_REQUEST_CLASS = true + get_url := CLASSIFY_HEAD + url.QueryEscape(targeturl) + if noimg { + get_url += "&noimg=true" + } + resp, err := http.Get(get_url) + if err != nil { + ctx.Send(fmt.Sprintf("ERROR: %v", err)) + } else { + if noimg { + data, err1 := ioutil.ReadAll(resp.Body) + if err1 == nil { + dhash := gjson.GetBytes(data, "img").String() + class := int(gjson.GetBytes(data, "class").Int()) + replyClass(ctx, dhash, class, noimg) + } else { + ctx.Send(fmt.Sprintf("ERROR: %v", err1)) + } + } else { + class, err1 := strconv.Atoi(resp.Header.Get("Class")) + dhash := resp.Header.Get("DHash") + if err1 != nil { + ctx.Send(fmt.Sprintf("ERROR: %v", err1)) + } + defer resp.Body.Close() + // 写入文件 + data, _ := ioutil.ReadAll(resp.Body) + f, _ := os.OpenFile(CACHE_IMG_FILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + defer f.Close() + f.Write(data) + replyClass(ctx, dhash, class, noimg) + } + } + BLOCK_REQUEST_CLASS = false + } +} + +func Vote(ctx *zero.Ctx, class int) { + msg, ok := msgofgrp[ctx.Event.GroupID] + if ok { + ctx.DeleteMessage(msg) + delete(msgofgrp, ctx.Event.GroupID) + dhash, ok2 := dhashofmsg[msg] + if ok2 { + http.Get(fmt.Sprintf(VOTE_API_URL, dhash, class)) + delete(dhashofmsg, msg) + } + } +} + +func replyClass(ctx *zero.Ctx, dhash string, class int, noimg bool) { + if class > 4 { + switch class { + case 5: + ctx.Send("[5]影响不好啦!") + case 6: + ctx.Send("[6]太涩啦,🐛了!") + } + if dhash != "" { + b14, err3 := url.QueryUnescape(dhash) + if err3 == nil { + ctx.Send("给你点提示哦:" + b14) + } + } + } else { + if !noimg { + last_message_id := ctx.Send(msgext.ImageNoCache(CACHE_URI)) + last_group_id := ctx.Event.GroupID + msgofgrp[last_group_id] = last_message_id + dhashofmsg[last_message_id] = dhash + } + switch class { + case 0: + ctx.Send("[0]一堆像素点") + case 1: + ctx.Send("[1]普通") + case 2: + ctx.Send("[2]有点意思") + case 3: + ctx.Send("[3]不错") + case 4: + ctx.Send("[4]我好啦!") + } + } +} diff --git a/api/context/pic.go b/api/context/pic.go new file mode 100644 index 00000000..ece057d7 --- /dev/null +++ b/api/context/pic.go @@ -0,0 +1,58 @@ +package context + +import ( + "strconv" + "time" + + zero "github.com/wdvxdr1123/ZeroBot" +) + +// HasPicture 消息含有图片返回 true +func HasPicture() zero.Rule { + return func(ctx *zero.Ctx) bool { + msg := ctx.Event.Message + url := []string{} + // 如果是回复信息则将信息替换成被回复的那条 + if msg[0].Type == "reply" { + id, _ := strconv.Atoi(msg[0].Data["id"]) + msg = ctx.GetMessage(int64(id)).Elements + } + // 遍历信息中所有图片 + for _, elem := range msg { + if elem.Type == "image" { + url = append(url, elem.Data["url"]) + } + } + // 如果有图片就返回true + if len(url) > 0 { + ctx.State["image_url"] = url + return true + } + return false + } +} + +// MustHasPicture 消息不存在图片阻塞60秒至有图片,超时返回 false +func MustHasPicture() zero.Rule { + return func(ctx *zero.Ctx) bool { + if HasPicture()(ctx) { + return true + } + // 没有图片就索取 + ctx.Send("请发送一张图片") + next := zero.NewFutureEvent("message", 999, false, zero.CheckUser(ctx.Event.UserID), HasPicture()) + recv, cancel := next.Repeat() + select { + case e := <-recv: + cancel() + newCtx := &zero.Ctx{Event: e, State: zero.State{}} + if HasPicture()(newCtx) { + ctx.State["image_url"] = newCtx.State["image_url"] + return true + } + return false + case <-time.After(time.Second * 60): + return false + } + } +} diff --git a/go.mod b/go.mod index 6e42b857..8e88710a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/antchfx/htmlquery v1.2.3 - github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210609110318-3c8ef99e3c6c + github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210616151841-d047372a50c2 github.com/mattn/go-sqlite3 v1.14.7 github.com/sirupsen/logrus v1.8.1 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 diff --git a/go.sum b/go.sum index 71f02a93..de1394bc 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210606064339-d55b94d71eee/go.mod h1:RN0gCtafWRu2d7lMg9/5UfZDhtsPgdeUovsyuSwl+oQ= github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210606075146-09f50acdb4de/go.mod h1:vG2ODqgJYFQobphBnhhmNv3TO+j/ZNYvN6FjUP/zkmA= -github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210609110318-3c8ef99e3c6c h1:M98iR1Em9EzfaduyhaO/I9Az3CVC0YS3pVbUihoPlM8= -github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210609110318-3c8ef99e3c6c/go.mod h1:/Tv1kgOdp76gvr1VoVmMG2Xu4c76vXngy6P8NFE4pA0= +github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210616151841-d047372a50c2 h1:8gJPxljHfnIFsE0ZfV8DJuI45Y+zTe/o2YtjKQRGYX8= +github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210616151841-d047372a50c2/go.mod h1:/Tv1kgOdp76gvr1VoVmMG2Xu4c76vXngy6P8NFE4pA0= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/picsearcher/pic_searcher.go b/picsearcher/pic_searcher.go index c33b1267..71c7cbbc 100644 --- a/picsearcher/pic_searcher.go +++ b/picsearcher/pic_searcher.go @@ -3,13 +3,12 @@ package picsearcher import ( "fmt" "os" - "strconv" "strings" - "time" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/context" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" apiutils "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils" @@ -48,7 +47,7 @@ func init() { // 插件主体 illust.RmPic(CACHEPATH) }) // 以图搜图 - zero.OnMessage(FullMatchText("以图搜图", "搜索图片", "以图识图"), MustHasPicture()).SetBlock(true).SetPriority(999). + zero.OnMessage(FullMatchText("以图搜图", "搜索图片", "以图识图"), context.MustHasPicture()).SetBlock(true).SetPriority(999). Handle(func(ctx *zero.Ctx) { // 开始搜索图片 ctx.Send("少女祈祷中......") @@ -90,53 +89,3 @@ func FullMatchText(src ...string) zero.Rule { return false } } - -// HasPicture 消息含有图片返回 true -func HasPicture() zero.Rule { - return func(ctx *zero.Ctx) bool { - msg := ctx.Event.Message - url := []string{} - // 如果是回复信息则将信息替换成被回复的那条 - if msg[0].Type == "reply" { - id, _ := strconv.Atoi(msg[0].Data["id"]) - msg = ctx.GetMessage(int64(id)).Elements - } - // 遍历信息中所有图片 - for _, elem := range msg { - if elem.Type == "image" { - url = append(url, elem.Data["url"]) - } - } - // 如果有图片就返回true - if len(url) > 0 { - ctx.State["image_url"] = url - return true - } - return false - } -} - -// MustHasPicture 消息不存在图片阻塞60秒至有图片,超时返回 false -func MustHasPicture() zero.Rule { - return func(ctx *zero.Ctx) bool { - if HasPicture()(ctx) { - return true - } - // 没有图片就索取 - ctx.Send("请发送一张图片") - next := zero.NewFutureEvent("message", 999, false, zero.CheckUser(ctx.Event.UserID), HasPicture()) - recv, cancel := next.Repeat() - select { - case e := <-recv: - cancel() - newCtx := &zero.Ctx{Event: e, State: zero.State{}} - if HasPicture()(newCtx) { - ctx.State["image_url"] = newCtx.State["image_url"] - return true - } - return false - case <-time.After(time.Second * 60): - return false - } - } -} diff --git a/randimg/setu_geter.go b/randimg/setu_geter.go index df40f02e..717d60ff 100644 --- a/randimg/setu_geter.go +++ b/randimg/setu_geter.go @@ -2,27 +2,21 @@ package randimg import ( "fmt" - "io/ioutil" - "net/http" - "net/url" - "os" - "strconv" "strings" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/classify" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/context" "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 = "http://127.0.0.1:62002/dice?url=" + RANDOM_API_URL - VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" - BLOCK_REQUEST_CLASS = false - BLOCK_REQUEST = false - CACHE_IMG_FILE = "/tmp/setugt" - CACHE_URI = "file:///" + CACHE_IMG_FILE - msgofgrp = make(map[int64]int64) - dhashofmsg = make(map[int64]string) + RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" + + BLOCK_REQUEST = false + + msgofgrp = make(map[int64]int64) + dhashofmsg = make(map[int64]string) ) func init() { // 插件主体 @@ -36,76 +30,16 @@ func init() { // 插件主体 } return }) - zero.OnRegex(`^设置评价图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20). + // 有保护的随机图片 + zero.OnFullMatch("随机图片").SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { - url := ctx.State["regex_matched"].([]string)[1] - if !strings.HasPrefix(url, "http") { - ctx.Send("URL非法!") - } else { - CLASSIFY_RANDOM_API_URL = url + RANDOM_API_URL + if ctx.Event.GroupID > 0 { + classify.Classify(ctx, RANDOM_API_URL, false) } return }) - // 有保护的随机图片 - if CLASSIFY_RANDOM_API_URL != "" { - zero.OnFullMatch("评价图片").SetBlock(true).SetPriority(24). - Handle(func(ctx *zero.Ctx) { - if ctx.Event.GroupID > 0 { - if BLOCK_REQUEST_CLASS { - ctx.Send("请稍后再试哦") - } else { - BLOCK_REQUEST_CLASS = true - resp, err := http.Get(CLASSIFY_RANDOM_API_URL) - if err != nil { - 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 { - defer resp.Body.Close() - // 写入文件 - data, _ := ioutil.ReadAll(resp.Body) - f, _ := os.OpenFile(CACHE_IMG_FILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - defer f.Close() - f.Write(data) - if class > 4 { - ctx.Send("太涩啦,不发了!") - if dhash != "" { - b14, err3 := url.QueryUnescape(dhash) - if err3 == nil { - ctx.Send("给你点提示哦:" + b14) - } - } - } else { - last_message_id := ctx.Send(msgext.ImageNoCache(CACHE_URI)) - last_group_id := ctx.Event.GroupID - msgofgrp[last_group_id] = last_message_id - dhashofmsg[last_message_id] = dhash - if class > 2 { - ctx.Send("我好啦!") - } - } - } - } - BLOCK_REQUEST_CLASS = false - } - } - return - }) - } - - zero.OnFullMatch("不许好").SetBlock(true).SetPriority(24). - Handle(func(ctx *zero.Ctx) { - vote(ctx, 5) - }) - zero.OnFullMatch("太涩了").SetBlock(true).SetPriority(24). - Handle(func(ctx *zero.Ctx) { - vote(ctx, 6) - }) - // 直接随机图片 - zero.OnFullMatch("随机图片").SetBlock(true).SetPriority(24). + // 直接随机图片,危险,仅管理员可用 + zero.OnFullMatch("直接随机", zero.AdminPermission).SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { if ctx.Event.GroupID > 0 { if BLOCK_REQUEST { @@ -120,17 +54,26 @@ func init() { // 插件主体 } return }) -} - -func vote(ctx *zero.Ctx, class int) { - msg, ok := msgofgrp[ctx.Event.GroupID] - if ok { - ctx.DeleteMessage(msg) - delete(msgofgrp, ctx.Event.GroupID) - dhash, ok2 := dhashofmsg[msg] - if ok2 { - http.Get(fmt.Sprintf(VOTE_API_URL, dhash, class)) - delete(dhashofmsg, msg) - } - } + // 撤回最后的随机图片 + zero.OnFullMatch("不许好").SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + classify.Vote(ctx, 5) + }) + // 撤回最后的随机图片 + zero.OnFullMatch("太涩了").SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + classify.Vote(ctx, 6) + }) + // 上传一张图进行评价 + zero.OnFullMatch("评价图片", context.MustHasPicture()).SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + if ctx.Event.GroupID > 0 { + ctx.Send("少女祈祷中......") + for _, pic := range ctx.State["image_url"].([]string) { + fmt.Println(pic) + classify.Classify(ctx, pic, true) + } + } + return + }) } From 3fc165d63613636f8a0b01ed95cc1a73fddae542 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sat, 19 Jun 2021 15:22:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?classify=E4=B8=8D=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/classify/classify.go | 72 ++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/api/classify/classify.go b/api/classify/classify.go index 619283be..72b3d025 100644 --- a/api/classify/classify.go +++ b/api/classify/classify.go @@ -14,53 +14,47 @@ import ( ) var ( - BLOCK_REQUEST_CLASS = false - CACHE_IMG_FILE = "/tmp/setugt" - CACHE_URI = "file:///" + CACHE_IMG_FILE - VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" - CLASSIFY_HEAD = "http://saki.fumiama.top:62002/dice?url=" - msgofgrp = make(map[int64]int64) - dhashofmsg = make(map[int64]string) + CACHE_IMG_FILE = "/tmp/setugt" + CACHE_URI = "file:///" + CACHE_IMG_FILE + VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" + CLASSIFY_HEAD = "http://saki.fumiama.top:62002/dice?url=" + msgofgrp = make(map[int64]int64) + dhashofmsg = make(map[int64]string) ) func Classify(ctx *zero.Ctx, targeturl string, noimg bool) { - if BLOCK_REQUEST_CLASS { - ctx.Send("请稍后再试哦") + + get_url := CLASSIFY_HEAD + url.QueryEscape(targeturl) + if noimg { + get_url += "&noimg=true" + } + resp, err := http.Get(get_url) + if err != nil { + ctx.Send(fmt.Sprintf("ERROR: %v", err)) } else { - BLOCK_REQUEST_CLASS = true - get_url := CLASSIFY_HEAD + url.QueryEscape(targeturl) if noimg { - get_url += "&noimg=true" - } - resp, err := http.Get(get_url) - if err != nil { - ctx.Send(fmt.Sprintf("ERROR: %v", err)) - } else { - if noimg { - data, err1 := ioutil.ReadAll(resp.Body) - if err1 == nil { - dhash := gjson.GetBytes(data, "img").String() - class := int(gjson.GetBytes(data, "class").Int()) - replyClass(ctx, dhash, class, noimg) - } else { - ctx.Send(fmt.Sprintf("ERROR: %v", err1)) - } - } else { - class, err1 := strconv.Atoi(resp.Header.Get("Class")) - dhash := resp.Header.Get("DHash") - if err1 != nil { - ctx.Send(fmt.Sprintf("ERROR: %v", err1)) - } - defer resp.Body.Close() - // 写入文件 - data, _ := ioutil.ReadAll(resp.Body) - f, _ := os.OpenFile(CACHE_IMG_FILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - defer f.Close() - f.Write(data) + data, err1 := ioutil.ReadAll(resp.Body) + if err1 == nil { + dhash := gjson.GetBytes(data, "img").String() + class := int(gjson.GetBytes(data, "class").Int()) replyClass(ctx, dhash, class, noimg) + } else { + ctx.Send(fmt.Sprintf("ERROR: %v", err1)) } + } else { + class, err1 := strconv.Atoi(resp.Header.Get("Class")) + dhash := resp.Header.Get("DHash") + if err1 != nil { + ctx.Send(fmt.Sprintf("ERROR: %v", err1)) + } + defer resp.Body.Close() + // 写入文件 + data, _ := ioutil.ReadAll(resp.Body) + f, _ := os.OpenFile(CACHE_IMG_FILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + defer f.Close() + f.Write(data) + replyClass(ctx, dhash, class, noimg) } - BLOCK_REQUEST_CLASS = false } } From 8b7749168a130e3e17444249fa73b2cdcf0fb1b5 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sat, 19 Jun 2021 15:46:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AF=84=E4=BB=B7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/classify/classify.go | 27 +++++++++++++++------------ api/context/pic.go | 1 + randimg/setu_geter.go | 8 ++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/api/classify/classify.go b/api/classify/classify.go index 72b3d025..9eaa15d2 100644 --- a/api/classify/classify.go +++ b/api/classify/classify.go @@ -11,6 +11,7 @@ import ( "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" "github.com/tidwall/gjson" zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" ) var ( @@ -18,12 +19,11 @@ var ( CACHE_URI = "file:///" + CACHE_IMG_FILE VOTE_API_URL = "http://saki.fumiama.top/vote?uuid=零号&img=%s&class=%d" CLASSIFY_HEAD = "http://saki.fumiama.top:62002/dice?url=" - msgofgrp = make(map[int64]int64) + MsgofGrp = make(map[int64]int64) dhashofmsg = make(map[int64]string) ) func Classify(ctx *zero.Ctx, targeturl string, noimg bool) { - get_url := CLASSIFY_HEAD + url.QueryEscape(targeturl) if noimg { get_url += "&noimg=true" @@ -59,10 +59,10 @@ func Classify(ctx *zero.Ctx, targeturl string, noimg bool) { } func Vote(ctx *zero.Ctx, class int) { - msg, ok := msgofgrp[ctx.Event.GroupID] + msg, ok := MsgofGrp[ctx.Event.GroupID] if ok { ctx.DeleteMessage(msg) - delete(msgofgrp, ctx.Event.GroupID) + delete(MsgofGrp, ctx.Event.GroupID) dhash, ok2 := dhashofmsg[msg] if ok2 { http.Get(fmt.Sprintf(VOTE_API_URL, dhash, class)) @@ -79,30 +79,33 @@ func replyClass(ctx *zero.Ctx, dhash string, class int, noimg bool) { case 6: ctx.Send("[6]太涩啦,🐛了!") } - if dhash != "" { + if dhash != "" && !noimg { b14, err3 := url.QueryUnescape(dhash) if err3 == nil { ctx.Send("给你点提示哦:" + b14) } } } else { + var last_message_id int64 if !noimg { - last_message_id := ctx.Send(msgext.ImageNoCache(CACHE_URI)) + last_message_id = ctx.Send(msgext.ImageNoCache(CACHE_URI)) last_group_id := ctx.Event.GroupID - msgofgrp[last_group_id] = last_message_id + MsgofGrp[last_group_id] = last_message_id dhashofmsg[last_message_id] = dhash + } else { + last_message_id = ctx.Event.MessageID } switch class { case 0: - ctx.Send("[0]一堆像素点") + ctx.SendChain(message.Reply(last_message_id), message.Text("[0]一堆像素点")) case 1: - ctx.Send("[1]普通") + ctx.SendChain(message.Reply(last_message_id), message.Text("[1]普通")) case 2: - ctx.Send("[2]有点意思") + ctx.SendChain(message.Reply(last_message_id), message.Text("[2]有点意思")) case 3: - ctx.Send("[3]不错") + ctx.SendChain(message.Reply(last_message_id), message.Text("[3]不错")) case 4: - ctx.Send("[4]我好啦!") + ctx.SendChain(message.Reply(last_message_id), message.Text("[4]我好啦!")) } } } diff --git a/api/context/pic.go b/api/context/pic.go index ece057d7..6cedef66 100644 --- a/api/context/pic.go +++ b/api/context/pic.go @@ -48,6 +48,7 @@ func MustHasPicture() zero.Rule { newCtx := &zero.Ctx{Event: e, State: zero.State{}} if HasPicture()(newCtx) { ctx.State["image_url"] = newCtx.State["image_url"] + ctx.Event.MessageID = newCtx.Event.MessageID return true } return false diff --git a/randimg/setu_geter.go b/randimg/setu_geter.go index 717d60ff..669b5168 100644 --- a/randimg/setu_geter.go +++ b/randimg/setu_geter.go @@ -12,11 +12,7 @@ import ( var ( RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" - - BLOCK_REQUEST = false - - msgofgrp = make(map[int64]int64) - dhashofmsg = make(map[int64]string) + BLOCK_REQUEST = false ) func init() { // 插件主体 @@ -48,7 +44,7 @@ func init() { // 插件主体 BLOCK_REQUEST = true last_message_id := ctx.Send(msgext.ImageNoCache(RANDOM_API_URL)) last_group_id := ctx.Event.GroupID - msgofgrp[last_group_id] = last_message_id + classify.MsgofGrp[last_group_id] = last_message_id BLOCK_REQUEST = false } }