chore(plugin): remove scale due to deletion

This commit is contained in:
源文雨 2024-04-11 16:35:39 +09:00
parent d7cdfb1544
commit 5c6af1af61
5 changed files with 6 additions and 167 deletions

View File

@ -1250,14 +1250,6 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 设置 saucenao api key [apikey]
</details>
<details>
<summary>叔叔的AI二次元图片放大</summary>
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/scale"`
- [x] 放大图片[图片]
</details>
<details>
<summary>签到得分</summary>

4
go.mod
View File

@ -4,8 +4,8 @@ go 1.20
require (
github.com/Baidu-AIP/golang-sdk v1.1.1
github.com/FloatTech/AnimeAPI v1.7.1-0.20240401063926-a06fe89b1362
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9

8
go.sum
View File

@ -2,10 +2,10 @@ github.com/Baidu-AIP/golang-sdk v1.1.1 h1:RQsAmgDSAkiq22I6n7XJ2t3afgzFeqjY46FGhv
github.com/Baidu-AIP/golang-sdk v1.1.1/go.mod h1:bXnGw7xPeKt8aF7UCELKrV6UZ/46spItONK1RQBQj1Y=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/FloatTech/AnimeAPI v1.7.1-0.20240401063926-a06fe89b1362 h1:llHNgb+UIj8q/2GgR+89pnUNwKQJvKx5EwsetLhJQcE=
github.com/FloatTech/AnimeAPI v1.7.1-0.20240401063926-a06fe89b1362/go.mod h1:7Olb5U9q1oeayRZQTNBhXQNMf8QT4T9hccsn38IEt/U=
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2 h1:O4kptIzgYzNwZlBARZFv8EkA40yB6M5LGxxIF7NKLR8=
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2/go.mod h1:TeTlp+hTxpJti4JSdmUqzxGEr4wUBOVct9YWBepilpc=
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d h1:eKJxkCzayyHPvQ7+uhF6acGBTnoq5c9K7J6sHbv6xwQ=
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d/go.mod h1:bNHsYcUd1+Y5Al3CR6tdzKxcc0XLivXjmUsL9xG6sSw=
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6 h1:Vaj8ulVbN8vTD4W7aj+BYeT6x8iKFneDnkgBCezomDY=
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6/go.mod h1:TeTlp+hTxpJti4JSdmUqzxGEr4wUBOVct9YWBepilpc=
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08 h1:dPLeoiTVSBlgls+66EB/UJ2e38BaASmBN5nANaycSBU=
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08/go.mod h1:uzPzAeT35egARdRuu+1oyjU3CmTwCceoq3Vvje7LpcI=
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef h1:CJbK/2FRwPuZpeb6M4sWK2d7oXDnBEGhpkQuQrgc91A=

View File

@ -129,7 +129,6 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/scale" // 叔叔的AI二次元图片放大
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/score" // 分数
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app

View File

@ -1,152 +0,0 @@
// Package scale 叔叔的AI二次元图片放大
package scale
import (
"bytes"
"image"
"math"
"os"
"strconv"
"time"
_ "image/gif" // import gif decoding
_ "image/jpeg" // import jpg decoding
_ "image/png" // import png decoding
_ "golang.org/x/image/webp" // import webp decoding
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/FloatTech/AnimeAPI/nsfw"
"github.com/FloatTech/AnimeAPI/scale"
"github.com/FloatTech/imgfactory"
"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/web"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
)
func init() {
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "二次元图片放大",
Help: "- 放大图片[图片]",
PrivateDataFolder: "scale",
}).ApplySingle(ctxext.DefaultSingle)
cachedir := engine.DataFolder()
// 上传一张图进行评价
engine.OnKeywordGroup([]string{"放大图片"}, zero.OnlyGroup, zero.MustProvidePicture, getPara).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
url := ctx.State["image_url"].([]string)
if len(url) > 0 {
datachan := make(chan []byte, 1)
var errsub error
go func() {
var d []byte
d, errsub = web.GetData(url[0])
datachan <- d
}()
ctx.SendChain(message.Text("少女祈祷中..."))
p, err := nsfw.Classify(url[0])
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if p.Drawings < 0.1 || p.Neutral > 0.8 {
ctx.SendChain(message.Text("请发送二次元图片!"))
return
}
data := <-datachan
if errsub != nil {
ctx.SendChain(message.Text("ERROR: ", errsub))
return
}
im, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
px := im.Bounds().Size().X * im.Bounds().Size().Y
paras := ctx.State["scale_paras"].([2]int)
if px > 512*512 {
px = int(math.Pow(float64(px), 0.5) + 0.5)
x := im.Bounds().Size().X * 512 / px
y := im.Bounds().Size().Y * 512 / px
ctx.SendChain(message.Text("图片", im.Bounds().Size().X, "x", im.Bounds().Size().Y, "过大,调整图片至", x, "x", y))
im = imgfactory.Size(im, x, y).Image()
w := binary.SelectWriter()
defer binary.PutWriter(w)
_, err = imgfactory.WriteTo(im, w)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
data, err = scale.Post(bytes.NewReader(w.Bytes()), paras[0], paras[1], 2)
} else {
data, err = scale.Get(url[0], paras[0], paras[1], 2)
}
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
n := cachedir + strconv.Itoa(int(ctx.Event.UserID))
f, err := os.Create(n)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
_, _ = f.Write(data)
_ = f.Close()
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + n))
}
})
}
func getPara(ctx *zero.Ctx) bool {
next := zero.NewFutureEvent("message", 999, false, ctx.CheckSession())
recv, cancel := next.Repeat()
i := 0
paras := [2]int{}
ctx.SendChain(message.Text("请输入模型序号\n0.", scale.Models[0], "\n1.", scale.Models[1], "\n2.", scale.Models[2], "\n3.", scale.Models[3], "\n4.", scale.Models[4]))
for {
select {
case <-time.After(time.Second * 120):
cancel()
return false
case c := <-recv:
msg := c.Event.Message.ExtractPlainText()
num, err := strconv.Atoi(msg)
if err != nil {
ctx.SendChain(message.Text("请输入数字!"))
continue
}
switch i {
case 0:
if num < 0 || num > 4 {
ctx.SendChain(message.Text("模型序号非法!"))
continue
}
paras[0] = num
ctx.SendChain(message.Text("请输入放大倍数(2-4)"))
case 1:
if num < 2 || num > 4 {
ctx.SendChain(message.Text("放大倍数非法!"))
continue
}
cancel()
paras[1] = num
ctx.State["scale_paras"] = paras
return true
}
i++
}
}
}