增加撤回

This commit is contained in:
fumiama 2021-06-17 19:57:45 +08:00
parent 2f360d1d8a
commit 8be003500c

View File

@ -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))
}