Skip to content

Commit d983c66

Browse files
committed
💫 🎉 ✨ 添加插件 DeepDanbooru二次元图标签识别
1 parent 30f6b57 commit d983c66

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
154154
- [x] 搜图[P站图片ID]
155155
- **搜番** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_tracemoe"`
156156
- [x] 搜番|搜索番剧[图片]
157-
- **随机图片与AI点评** `github.com/FloatTech/ZeroBot-Plugin/plugin_acgimage`
157+
- **随机图片与AI点评** `import _ github.com/FloatTech/ZeroBot-Plugin/plugin_acgimage`
158158
- [x] 随机图片(评级大于6的图将私发)
159159
- [x] 直接随机(无r18检测,务必小心,仅管理可用)
160160
- [x] 设置随机图片网址[url]
161161
- [x] 太涩了(撤回最近发的图)
162162
- [x] 评价图片(发送一张图片让bot评分)
163+
- **DeepDanbooru二次元图标签识别** `import _ github.com/FloatTech/ZeroBot-Plugin/plugin_danbooru`
164+
- [x] 鉴赏图片[图片]
163165
- **每日运势** `import _ github.com/FloatTech/ZeroBot-Plugin/plugin_fortune`
164166
- [x] 运势|抽签
165167
- [x] 设置底图[车万 DC4 爱因斯坦 星空列车 樱云之恋 富婆妹 李清歌 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师]

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import (
5858
// 二次元图片
5959
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_acgimage" // 随机图片与AI点评
6060
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_aiwife" // 随机老婆
61+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_danbooru" // d
6162
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder" // 关键字搜图
6263
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片
6364
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativesetu" // 本地涩图

plugin_danbooru/main.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Package deepdanbooru 二次元图片标签识别
2+
package deepdanbooru
3+
4+
import (
5+
"crypto/md5"
6+
"encoding/hex"
7+
"os"
8+
9+
"github.com/FloatTech/AnimeAPI/danbooru"
10+
"github.com/FloatTech/AnimeAPI/picture"
11+
"github.com/FloatTech/AnimeAPI/saucenao"
12+
"github.com/FloatTech/zbputils/control"
13+
"github.com/FloatTech/zbputils/file"
14+
zero "github.com/wdvxdr1123/ZeroBot"
15+
"github.com/wdvxdr1123/ZeroBot/message"
16+
"github.com/wdvxdr1123/ZeroBot/utils/helper"
17+
)
18+
19+
const cachefile = "data/danbooru/"
20+
21+
func init() { // 插件主体
22+
err := os.MkdirAll(cachefile, 0755)
23+
if err != nil {
24+
panic(err)
25+
}
26+
engine := control.Register("danbooru", &control.Options{
27+
DisableOnDefault: false,
28+
Help: "二次元图片标签识别\n" +
29+
"- 鉴赏图片[图片]",
30+
})
31+
// 上传一张图进行评价
32+
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true).SetPriority(23).
33+
Handle(func(ctx *zero.Ctx) {
34+
ctx.SendChain(message.Text("少女祈祷中..."))
35+
for _, url := range ctx.State["image_url"].([]string) {
36+
name := ""
37+
r, err := saucenao.SauceNAO(url)
38+
if err != nil {
39+
name = "未知图片"
40+
} else {
41+
name = r.Title
42+
}
43+
t, err := danbooru.TagURL(name, url)
44+
if err != nil {
45+
ctx.SendChain(message.Text("ERROR:", err))
46+
return
47+
}
48+
digest := md5.Sum(helper.StringToBytes(url))
49+
f := cachefile + hex.EncodeToString(digest[:])
50+
if file.IsNotExist(f) {
51+
t.Canvas.SavePNG(f)
52+
}
53+
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + f))
54+
}
55+
})
56+
}

0 commit comments

Comments
 (0)