上一个随机图片未完成前拒绝请求

This commit is contained in:
fumiama 2021-06-04 13:51:37 +08:00
parent 08b2102528
commit 352fd2eb79
3 changed files with 10 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import (
"strconv"
"strings"
"github.com/Yiwen-Chan/ZeroBot-Plugin/msgext"
"github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

View File

@ -3,11 +3,12 @@ package randimg
import (
"strings"
"github.com/Yiwen-Chan/ZeroBot-Plugin/msgext"
"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"
var BLOCK_REQUEST = false
func init() { // 插件主体
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
@ -23,7 +24,13 @@ func init() { // 插件主体
// 随机图片
zero.OnFullMatchGroup([]string{"随机图片"}).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
ctx.Send(msgext.ImageNoCache(RANDOM_API_URL))
if BLOCK_REQUEST {
ctx.Send("请稍后再试哦")
} else {
BLOCK_REQUEST = true
ctx.Send(msgext.ImageNoCache(RANDOM_API_URL))
BLOCK_REQUEST = false
}
return
})
}