mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
带分类识别的随机
This commit is contained in:
parent
91d13c12b2
commit
2f360d1d8a
@ -1,14 +1,25 @@
|
|||||||
package randimg
|
package randimg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext"
|
"github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img"
|
var (
|
||||||
var BLOCK_REQUEST = false
|
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
|
||||||
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
|
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
|
||||||
@ -22,14 +33,50 @@ func init() { // 插件主体
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
// 随机图片
|
// 随机图片
|
||||||
zero.OnFullMatchGroup([]string{"随机图片"}).SetBlock(true).SetPriority(24).
|
zero.OnFullMatch("随机图片").SetBlock(true).SetPriority(24).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
if BLOCK_REQUEST {
|
if ctx.Event.GroupID > 0 {
|
||||||
ctx.Send("请稍后再试哦")
|
if BLOCK_REQUEST {
|
||||||
} else {
|
ctx.Send("请稍后再试哦")
|
||||||
BLOCK_REQUEST = true
|
} else {
|
||||||
ctx.Send(msgext.ImageNoCache(RANDOM_API_URL))
|
BLOCK_REQUEST = true
|
||||||
BLOCK_REQUEST = false
|
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"))
|
||||||
|
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("太涩啦,不发了!")
|
||||||
|
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))
|
||||||
|
if class > 2 {
|
||||||
|
ctx.Send("我好啦!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Send(msgext.ImageNoCache(RANDOM_API_URL))
|
||||||
|
}
|
||||||
|
BLOCK_REQUEST = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user