Skip to content

Commit

Permalink
增加撤回
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jun 17, 2021
1 parent d922158 commit 5d490be
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions randimg/setu_geter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() { // 插件主体
Expand All @@ -36,16 +41,18 @@ 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)
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 {
Expand All @@ -57,15 +64,15 @@ 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 {
ctx.Send("给你点提示哦:" + b14)
}
}
} else {
ctx.Send(msgext.ImageNoCache(CACHE_URI))
last_message_id = ctx.Send(msgext.ImageNoCache(CACHE_URI))
last_dhash = dhash
if class > 2 {
ctx.Send("我好啦!")
}
Expand All @@ -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))
}

0 comments on commit 5d490be

Please sign in to comment.