mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
🔥 ✨ use new imgpool
This commit is contained in:
parent
e0317d1fe1
commit
da5aab3ee6
4
go.mod
4
go.mod
@ -3,8 +3,8 @@ module github.com/FloatTech/ZeroBot-Plugin
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix3
|
||||
github.com/FloatTech/zbputils v1.2.4-fix2
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix10
|
||||
github.com/FloatTech/zbputils v1.2.4-fix6
|
||||
github.com/antchfx/htmlquery v1.2.4
|
||||
github.com/corona10/goimagehash v1.0.3
|
||||
github.com/fogleman/gg v1.3.0
|
||||
|
||||
8
go.sum
8
go.sum
@ -1,8 +1,8 @@
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix3 h1:WlaEPjpNzmVgHriR7V5RDxRPNYX8gN1xqaJP9rQBul8=
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix3/go.mod h1:h4Re10eTkkhCVrrftL8PbJm6OHlVxdGSdjvXQ7/opoM=
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix10 h1:+wZ/9V+VuQtai47jrIGH6MEZfp096123RiYA+J8Er3g=
|
||||
github.com/FloatTech/AnimeAPI v1.2.4-fix10/go.mod h1:V+cIUIRxFsKniFqC2zfaT+2rhZQ0fIE0K+fWo+0qEpk=
|
||||
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
||||
github.com/FloatTech/zbputils v1.2.4-fix2 h1:CfiJ/owSgB4UOm4esGh0ZKxARW/Pw9zHrV0QLUwSX0k=
|
||||
github.com/FloatTech/zbputils v1.2.4-fix2/go.mod h1:ZXKT80QiMNZ2EP9Ga69hzjo3PV+NVrS9zZdJ9njNqWE=
|
||||
github.com/FloatTech/zbputils v1.2.4-fix6 h1:dEoOyYdCg05XhRivLU1CWNBzvzqv2hrJkv+eHXdOO0A=
|
||||
github.com/FloatTech/zbputils v1.2.4-fix6/go.mod h1:ZXKT80QiMNZ2EP9Ga69hzjo3PV+NVrS9zZdJ9njNqWE=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
|
||||
22
main.go
22
main.go
@ -71,8 +71,6 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation" // vtb语录
|
||||
|
||||
// 以下为内置依赖,勿动
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/fumiama/go-registry"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
@ -87,14 +85,13 @@ var (
|
||||
"* Copyright © 2020 - 2021 FloatTech. All Rights Reserved.",
|
||||
"* Project: https://github.com/FloatTech/ZeroBot-Plugin",
|
||||
}
|
||||
nicks = []string{"ATRI", "atri", "亚托莉", "アトリ"}
|
||||
banner = strings.Join(contents, "\n")
|
||||
token *string
|
||||
url *string
|
||||
adana *string
|
||||
prefix *string
|
||||
poolkey *string
|
||||
reg = registry.NewRegReader("reilia.fumiama.top:32664", "fumiama")
|
||||
nicks = []string{"ATRI", "atri", "亚托莉", "アトリ"}
|
||||
banner = strings.Join(contents, "\n")
|
||||
token *string
|
||||
url *string
|
||||
adana *string
|
||||
prefix *string
|
||||
reg = registry.NewRegReader("reilia.fumiama.top:32664", "fumiama")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -112,7 +109,6 @@ func init() {
|
||||
// 默认昵称
|
||||
adana = flag.String("n", "椛椛", "Set default nickname.")
|
||||
prefix = flag.String("p", "/", "Set command prefix.")
|
||||
poolkey = flag.String("pk", "", "Set imgpool key and enable listening.")
|
||||
|
||||
flag.Parse()
|
||||
if *h {
|
||||
@ -129,10 +125,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
if *poolkey != "" {
|
||||
imgpool.RegisterListener(*poolkey, control.Register("imgpool", 1, &control.Options{}))
|
||||
}
|
||||
|
||||
// 启用 gui
|
||||
// webctrl.InitGui(*g)
|
||||
}
|
||||
|
||||
@ -8,15 +8,15 @@ import (
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/classify"
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/order"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -54,7 +54,7 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
// 有保护的随机图片
|
||||
engine.OnFullMatch("随机图片", zero.OnlyPublic).SetBlock(true).
|
||||
engine.OnFullMatch("随机图片", zero.OnlyGroup).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if limit.Load(ctx.Event.UserID).Acquire() {
|
||||
class, dhash, comment, _ := classify.Classify(randapi, true)
|
||||
@ -110,15 +110,10 @@ func init() { // 插件主体
|
||||
u = apihead + dhash
|
||||
}
|
||||
|
||||
m, err := imgpool.NewImage(ctx, dhash, u)
|
||||
var img message.MessageSegment
|
||||
if err != nil {
|
||||
img = message.Image(u)
|
||||
} else {
|
||||
img = message.Image(m.String())
|
||||
_, err := imgpool.NewImage(ctxext.Send(ctx), ctxext.GetMessage(ctx), dhash, u)
|
||||
if err != nil && err.Error() == "send image error" {
|
||||
ctx.SendChain(message.Image(u))
|
||||
}
|
||||
|
||||
ctx.SendChain(img)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -128,6 +123,11 @@ func setLastMsg(id int64, msg message.MessageID) {
|
||||
}
|
||||
|
||||
func replyClass(ctx *zero.Ctx, class int, dhash string, comment string, isupload bool) {
|
||||
if isupload {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(comment))
|
||||
return
|
||||
}
|
||||
|
||||
b14, err := url.QueryUnescape(dhash)
|
||||
if err != nil {
|
||||
return
|
||||
@ -140,28 +140,27 @@ func replyClass(ctx *zero.Ctx, class int, dhash string, comment string, isupload
|
||||
u = apihead + dhash
|
||||
}
|
||||
|
||||
m, err := imgpool.NewImage(ctx, b14, u)
|
||||
var img message.MessageSegment
|
||||
if err != nil {
|
||||
img = message.Image(u)
|
||||
var send ctxext.NoCtxSendMsg
|
||||
if class > 5 {
|
||||
send = ctxext.SendTo(ctx, ctx.Event.UserID)
|
||||
} else {
|
||||
img = message.Image(m.String())
|
||||
send = func(msg interface{}) int64 {
|
||||
return ctx.Send(append(msg.(message.Message), message.Text(comment))).ID()
|
||||
}
|
||||
}
|
||||
|
||||
if class > 5 {
|
||||
if dhash != "" && !isupload {
|
||||
if dhash != "" {
|
||||
ctx.SendChain(message.Text(comment + "\n给你点提示哦:" + b14))
|
||||
ctx.Event.GroupID = 0
|
||||
ctx.Event.DetailType = "private"
|
||||
ctx.SendChain(img)
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text(comment))
|
||||
return
|
||||
}
|
||||
if isupload {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(comment))
|
||||
return
|
||||
|
||||
_, err = imgpool.NewImage(send, ctxext.GetMessage(ctx), b14, u)
|
||||
if err != nil && err.Error() == "send image error" {
|
||||
logrus.Debugln("[acgimage]", err)
|
||||
img := message.Image(u)
|
||||
ctx.SendChain(img, message.Text(comment))
|
||||
}
|
||||
ctx.SendChain(img, message.Text(comment))
|
||||
}
|
||||
|
||||
@ -21,9 +21,9 @@ import (
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/math"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
"github.com/FloatTech/zbputils/txt2img"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/order"
|
||||
@ -147,7 +147,7 @@ func init() {
|
||||
digest := md5.Sum(helper.StringToBytes(zipfile + strconv.Itoa(index) + title + text))
|
||||
cachefile := cache + hex.EncodeToString(digest[:])
|
||||
|
||||
m, err := imgpool.GetImage(ctx, cachefile)
|
||||
m, err := imgpool.GetImage(cachefile)
|
||||
if err != nil {
|
||||
logrus.Debugln("[fortune]", err)
|
||||
if file.IsNotExist(cachefile) {
|
||||
@ -163,21 +163,16 @@ func init() {
|
||||
return
|
||||
}
|
||||
}
|
||||
m, err = imgpool.NewImage(ctx, cachefile, file.BOTPATH+"/"+cachefile)
|
||||
process.SleepAbout1sTo2s() // 防止风控
|
||||
if err != nil {
|
||||
m.SetFile(file.BOTPATH + "/" + cachefile)
|
||||
err = m.Push(ctxext.Send(ctx), ctxext.GetMessage(ctx))
|
||||
if err != nil && err.Error() == "send image error" {
|
||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + cachefile))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 发送图片
|
||||
ctx.SendChain(message.Image(m.String()))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
|
||||
// 发送图片
|
||||
ctx.SendChain(message.Image(m.String()))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
@ -76,12 +77,10 @@ func init() {
|
||||
rannum := randintn(len(soutujson.Illusts))
|
||||
pom2 := soutujson.Illusts[rannum].ImageUrls.Medium[19:]
|
||||
u := pom1 + pom2
|
||||
m, err := imgpool.NewImage(ctx, u[strings.LastIndex(u, "/")+1:], u)
|
||||
if err != nil {
|
||||
_, err := imgpool.NewImage(ctxext.Send(ctx), ctxext.GetMessage(ctx), u[strings.LastIndex(u, "/")+1:], u)
|
||||
if err != nil && err.Error() == "send image error" {
|
||||
ctx.SendChain(message.Image(u))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Image(m.String()))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/math"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
|
||||
@ -56,9 +57,10 @@ func init() {
|
||||
url := json.Get("data.0.urls.original").Str
|
||||
url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re")
|
||||
name := url[strings.LastIndex(url, "/")+1 : len(url)-4]
|
||||
m, err := imgpool.GetImage(ctx, name)
|
||||
m, err := imgpool.GetImage(name)
|
||||
if err != nil {
|
||||
m, err = imgpool.NewImage(ctx, name, url)
|
||||
m.SetFile(url)
|
||||
err = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
|
||||
process.SleepAbout1sTo2s()
|
||||
}
|
||||
if err == nil {
|
||||
@ -69,7 +71,7 @@ func init() {
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-time.After(time.Second * 10):
|
||||
case <-time.After(time.Minute):
|
||||
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
|
||||
case url := <-queue:
|
||||
ctx.SendChain(message.Image(url))
|
||||
|
||||
@ -10,15 +10,15 @@ import (
|
||||
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||
"github.com/FloatTech/AnimeAPI/saucenao"
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/order"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -70,10 +70,12 @@ func init() { // 插件主体
|
||||
}
|
||||
}
|
||||
if f != "" {
|
||||
m, err := imgpool.NewImage(ctx, n, f)
|
||||
m, err := imgpool.NewImage(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx), n, f)
|
||||
if err == nil {
|
||||
imgs = append(imgs, message.Image(m.String()))
|
||||
process.SleepAbout1sTo2s()
|
||||
} else {
|
||||
logrus.Debugln("[saucenao]", err)
|
||||
imgs = append(imgs, message.Image("file:///"+f))
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,19 +9,20 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
imagepool "github.com/FloatTech/AnimeAPI/imgpool"
|
||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/order"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
fileutil "github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/math"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
"github.com/FloatTech/zbputils/rule"
|
||||
"github.com/FloatTech/zbputils/sql"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/order"
|
||||
)
|
||||
|
||||
// Pools 图片缓冲池
|
||||
@ -77,114 +78,106 @@ func init() { // 插件主体
|
||||
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- >setu status",
|
||||
})
|
||||
go func() {
|
||||
process.SleepAbout1sTo2s()
|
||||
pool = newPools()
|
||||
engine.OnRegex(`^来份(.*)$`, rule.FirstValueInList(pool.List)).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
||||
return
|
||||
}
|
||||
var imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
// 补充池子
|
||||
go func() {
|
||||
times := math.Min(pool.Max-pool.size(imgtype), 2)
|
||||
for i := 0; i < times; i++ {
|
||||
illust := &pixiv.Illust{}
|
||||
// 查询出一张图片
|
||||
if err := pool.DB.Pick(imgtype, illust); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
// 下载图片
|
||||
if err := download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))})
|
||||
// 向缓冲池添加一张图片
|
||||
pool.push(imgtype, illust)
|
||||
time.Sleep(time.Second * 1)
|
||||
process.SleepAbout1sTo2s()
|
||||
pool = newPools()
|
||||
engine.OnRegex(`^来份(.*)$`, rule.FirstValueInList(pool.List)).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
||||
return
|
||||
}
|
||||
var imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
// 补充池子
|
||||
go func() {
|
||||
times := math.Min(pool.Max-pool.size(imgtype), 2)
|
||||
for i := 0; i < times; i++ {
|
||||
illust := &pixiv.Illust{}
|
||||
// 查询出一张图片
|
||||
if err := pool.DB.Pick(imgtype, illust); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
}()
|
||||
// 如果没有缓存,阻塞5秒
|
||||
// 向缓冲池添加一张图片
|
||||
pool.push(ctx, imgtype, illust)
|
||||
process.SleepAbout1sTo2s()
|
||||
}
|
||||
}()
|
||||
// 如果没有缓存,阻塞10秒
|
||||
if pool.size(imgtype) == 0 {
|
||||
ctx.SendChain(message.Text("INFO: 正在填充弹药......"))
|
||||
time.Sleep(time.Second * 10)
|
||||
if pool.size(imgtype) == 0 {
|
||||
ctx.SendChain(message.Text("INFO: 正在填充弹药......"))
|
||||
<-time.After(time.Second * 5)
|
||||
if pool.size(imgtype) == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
|
||||
return
|
||||
}
|
||||
// 从缓冲池里抽一张
|
||||
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
})
|
||||
}
|
||||
// 从缓冲池里抽一张
|
||||
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
})
|
||||
|
||||
engine.OnRegex(`^添加(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||
)
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
// 查询P站插图信息
|
||||
illust, err := pixiv.Works(id)
|
||||
engine.OnRegex(`^添加(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||
)
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
// 查询P站插图信息
|
||||
illust, err := pixiv.Works(id)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
// 下载插画
|
||||
if err := download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
// 发送到发送者
|
||||
if id := ctx.SendChain(message.Image(file(illust))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败"))
|
||||
return
|
||||
}
|
||||
// 添加插画到对应的数据库table
|
||||
if err := pool.DB.Insert(imgtype, illust); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("添加成功"))
|
||||
})
|
||||
|
||||
engine.OnRegex(`^删除(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||
)
|
||||
// 查询数据库
|
||||
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("删除成功"))
|
||||
})
|
||||
|
||||
// 查询数据库涩图数量
|
||||
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
state := []string{"[SetuTime]"}
|
||||
for i := range pool.List {
|
||||
num, err := pool.DB.Count(pool.List[i])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
num = 0
|
||||
}
|
||||
// 下载插画
|
||||
if err := download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
// 发送到发送者
|
||||
if id := ctx.SendChain(message.Image(file(illust))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败"))
|
||||
return
|
||||
}
|
||||
// 添加插画到对应的数据库table
|
||||
if err := pool.DB.Insert(imgtype, illust); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("添加成功"))
|
||||
})
|
||||
|
||||
engine.OnRegex(`^删除(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||
)
|
||||
// 查询数据库
|
||||
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("删除成功"))
|
||||
})
|
||||
|
||||
// 查询数据库涩图数量
|
||||
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
state := []string{"[SetuTime]"}
|
||||
for i := range pool.List {
|
||||
num, err := pool.DB.Count(pool.List[i])
|
||||
if err != nil {
|
||||
num = 0
|
||||
}
|
||||
state = append(state, "\n")
|
||||
state = append(state, pool.List[i])
|
||||
state = append(state, ": ")
|
||||
state = append(state, fmt.Sprintf("%d", num))
|
||||
}
|
||||
ctx.SendChain(message.Text(state))
|
||||
})
|
||||
}()
|
||||
state = append(state, "\n")
|
||||
state = append(state, pool.List[i])
|
||||
state = append(state, ": ")
|
||||
state = append(state, fmt.Sprintf("%d", num))
|
||||
}
|
||||
ctx.SendChain(message.Text(state))
|
||||
})
|
||||
}
|
||||
|
||||
// size 返回缓冲池指定类型的现有大小
|
||||
@ -199,10 +192,22 @@ func (p *imgpool) isFull(imgtype string) bool {
|
||||
}*/
|
||||
|
||||
// push 向缓冲池插入一张图片
|
||||
func (p *imgpool) push(imgtype string, illust *pixiv.Illust) {
|
||||
func (p *imgpool) push(ctx *zero.Ctx, imgtype string, illust *pixiv.Illust) {
|
||||
u := illust.ImageUrls[0]
|
||||
n := u[strings.LastIndex(u, "/")+1 : len(u)-4]
|
||||
m, err := imagepool.GetImage(n)
|
||||
if err != nil {
|
||||
// 下载图片
|
||||
if err = download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
m.SetFile(strings.ReplaceAll(n, "_p0", ""))
|
||||
_ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
|
||||
}
|
||||
p.Lock.Lock()
|
||||
defer p.Lock.Unlock()
|
||||
p.Pool[imgtype] = append(p.Pool[imgtype], illust)
|
||||
p.Lock.Unlock()
|
||||
}
|
||||
|
||||
// Push 在缓冲池拿出一张图片
|
||||
@ -218,31 +223,30 @@ func (p *imgpool) pop(imgtype string) (illust *pixiv.Illust) {
|
||||
}
|
||||
|
||||
func file(i *pixiv.Illust) string {
|
||||
u := i.ImageUrls[0]
|
||||
m, err := imagepool.GetImage(u[strings.LastIndex(u, "/")+1 : len(u)-4])
|
||||
if err == nil {
|
||||
return m.String()
|
||||
}
|
||||
filename := fmt.Sprint(i.Pid)
|
||||
filepath := fileutil.BOTPATH + `/` + pool.Path + filename
|
||||
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
|
||||
if fileutil.IsExist(filepath + ".jpg") {
|
||||
return `file:///` + filepath + ".jpg"
|
||||
}
|
||||
if _, err := os.Stat(filepath + ".png"); err == nil || os.IsExist(err) {
|
||||
if fileutil.IsExist(filepath + ".png") {
|
||||
return `file:///` + filepath + ".png"
|
||||
}
|
||||
if _, err := os.Stat(filepath + ".gif"); err == nil || os.IsExist(err) {
|
||||
if fileutil.IsExist(filepath + ".gif") {
|
||||
return `file:///` + filepath + ".gif"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ {
|
||||
func download(i *pixiv.Illust, filedir string) error {
|
||||
filename := fmt.Sprint(i.Pid)
|
||||
filepath := filedir + filename
|
||||
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
|
||||
return /*filepath + ".jpg",*/ nil
|
||||
}
|
||||
if _, err := os.Stat(filepath + ".png"); err == nil || os.IsExist(err) {
|
||||
return /*filepath + ".png",*/ nil
|
||||
}
|
||||
if _, err := os.Stat(filepath + ".gif"); err == nil || os.IsExist(err) {
|
||||
return /*filepath + ".gif",*/ nil
|
||||
if fileutil.IsExist(filepath+".jpg") || fileutil.IsExist(filepath+".png") || fileutil.IsExist(filepath+".gif") {
|
||||
return nil
|
||||
}
|
||||
// 下载最大分辨率为 1200 的图片
|
||||
link := i.ImageUrls[0]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user