Skip to content

Commit fc0d020

Browse files
committed
✨ 新增叔叔的放大图片
1 parent 617e2c9 commit fc0d020

File tree

8 files changed

+113
-5
lines changed

8 files changed

+113
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
167167
- [x] 评价图片(发送一张图片让bot评分)
168168
- **DeepDanbooru二次元图标签识别** `import _ github.com/FloatTech/ZeroBot-Plugin/plugin_danbooru`
169169
- [x] 鉴赏图片[图片]
170+
- **叔叔的AI二次元图片放大** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_scale"`
171+
- [x] 放大图片[图片]
170172
- **每日运势** `import _ github.com/FloatTech/ZeroBot-Plugin/plugin_fortune`
171173
- [x] 运势 | 抽签
172174
- [x] 设置底图[车万 DC4 爱因斯坦 星空列车 樱云之恋 富婆妹 李清歌 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师 赛马娘]

data

Submodule data updated 1 file

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import (
6969
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativewife" // 本地老婆
7070
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nsfw" // nsfw图片识别
7171
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao" // 以图搜图
72+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_scale" // 叔叔的AI二次元图片放大
7273
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime" // 来份涩图
7374
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_tracemoe" // 搜番
7475
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation" // vtb语录

order/prio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
PrioReborn
4545
PrioRuncode
4646
PrioSauceNao
47+
PrioScale
4748
PrioScore
4849
PrioSetuTime
4950
PrioShaDiao

plugin_acgimage/classify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func init() { // 插件主体
8989
}
9090
})
9191
// 上传一张图进行评价
92-
engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyPublic, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
92+
engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
9393
Handle(func(ctx *zero.Ctx) {
9494
ctx.SendChain(message.Text("少女祈祷中..."))
9595
for _, url := range ctx.State["image_url"].([]string) {

plugin_danbooru/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() { // 插件主体
3232
"- 鉴赏图片[图片]",
3333
})
3434
// 上传一张图进行评价
35-
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyPublic, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
35+
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyGroup, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
3636
Handle(func(ctx *zero.Ctx) {
3737
ctx.SendChain(message.Text("少女祈祷中..."))
3838
for _, url := range ctx.State["image_url"].([]string) {

plugin_nsfw/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func init() {
1616
Help: "nsfw图片识别\n- nsfw打分[图片]",
1717
})
1818
// 上传一张图进行评价
19-
engine.OnKeywordGroup([]string{"nsfw打分"}, zero.OnlyPublic, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
19+
engine.OnKeywordGroup([]string{"nsfw打分"}, zero.OnlyGroup, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true).
2020
Handle(func(ctx *zero.Ctx) {
2121
url := ctx.State["image_url"].([]string)
2222
if len(url) > 0 {
@@ -51,7 +51,7 @@ func judge(p nsfw.Picture) string {
5151
return "普通哦"
5252
}
5353
c := ""
54-
if p.Drawings > 0.3 {
54+
if p.Drawings > 0.3 || p.Neutral < 0.3 {
5555
c = "二次元"
5656
} else {
5757
c = "三次元"

plugin_scale/main.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Package scale 叔叔的AI二次元图片放大
2+
package scale
3+
4+
import (
5+
"os"
6+
"strconv"
7+
"time"
8+
9+
"github.com/FloatTech/AnimeAPI/nsfw"
10+
"github.com/FloatTech/AnimeAPI/scale"
11+
"github.com/FloatTech/zbputils/control"
12+
"github.com/FloatTech/zbputils/ctxext"
13+
"github.com/FloatTech/zbputils/file"
14+
zero "github.com/wdvxdr1123/ZeroBot"
15+
"github.com/wdvxdr1123/ZeroBot/message"
16+
17+
"github.com/FloatTech/ZeroBot-Plugin/order"
18+
)
19+
20+
const cachedir = "data/scale/"
21+
22+
func init() {
23+
_ = os.RemoveAll(cachedir)
24+
err := os.MkdirAll(cachedir, 0755)
25+
if err != nil {
26+
panic(err)
27+
}
28+
engine := control.Register("scale", order.PrioScale, &control.Options{
29+
DisableOnDefault: false,
30+
Help: "叔叔的AI二次元图片放大\n- 放大图片[图片]",
31+
})
32+
// 上传一张图进行评价
33+
engine.OnKeywordGroup([]string{"放大图片"}, zero.OnlyGroup, ctxext.CmdMatch, ctxext.MustGiven, getPara).SetBlock(true).
34+
Handle(func(ctx *zero.Ctx) {
35+
url := ctx.State["image_url"].([]string)
36+
if len(url) > 0 {
37+
ctx.SendChain(message.Text("少女祈祷中..."))
38+
p, err := nsfw.Classify(url[0])
39+
if err != nil {
40+
ctx.SendChain(message.Text("ERROR:", err))
41+
return
42+
}
43+
if p[0].Drawings < 0.1 || p[0].Neutral > 0.8 {
44+
ctx.SendChain(message.Text("请发送二次元图片!"))
45+
return
46+
}
47+
paras := ctx.State["scale_paras"].([2]int)
48+
data, err := scale.Get(url[0], paras[0], paras[1], 2)
49+
if err != nil {
50+
ctx.SendChain(message.Text("ERROR:", err))
51+
return
52+
}
53+
n := cachedir + strconv.Itoa(int(ctx.Event.UserID))
54+
f, err := os.Create(n)
55+
if err != nil {
56+
ctx.SendChain(message.Text("ERROR:", err))
57+
return
58+
}
59+
f.Write(data)
60+
f.Close()
61+
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + n))
62+
}
63+
})
64+
}
65+
66+
func getPara(ctx *zero.Ctx) bool {
67+
next := zero.NewFutureEvent("message", 999, false, zero.CheckUser(ctx.Event.UserID))
68+
recv, cancel := next.Repeat()
69+
i := 0
70+
paras := [2]int{}
71+
ctx.SendChain(message.Text("请输入模型序号\n0.", scale.Models[0], "\n1.", scale.Models[1], "\n2.", scale.Models[2], "\n3.", scale.Models[3], "\n4.", scale.Models[4]))
72+
for {
73+
select {
74+
case <-time.After(time.Second * 120):
75+
return false
76+
case e := <-recv:
77+
msg := e.Message.ExtractPlainText()
78+
num, err := strconv.Atoi(msg)
79+
if err != nil {
80+
ctx.SendChain(message.Text("请输入数字!"))
81+
continue
82+
}
83+
switch i {
84+
case 0:
85+
if num < 0 || num > 4 {
86+
ctx.SendChain(message.Text("模型序号非法!"))
87+
continue
88+
}
89+
paras[0] = num
90+
ctx.SendChain(message.Text("请输入放大倍数(2-4)"))
91+
case 1:
92+
if num < 2 || num > 4 {
93+
ctx.SendChain(message.Text("放大倍数非法!"))
94+
continue
95+
}
96+
cancel()
97+
paras[1] = num
98+
ctx.State["scale_paras"] = paras
99+
return true
100+
}
101+
i++
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)