nonebot-plugin-savepic 0.2.5__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/PKG-INFO +1 -1
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/__init__.py +23 -101
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/config.py +14 -1
- nonebot_plugin_savepic-0.2.7/nonebot_plugin_savepic/mvpic.py +146 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/pic_sql.py +41 -41
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/rule.py +2 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/pyproject.toml +1 -1
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/LICENSE +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/README.md +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ai_utils.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/countpic.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/error.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ext_listener.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/model.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/networks/__init__.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/networks/resnet_big.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/picture.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/randpic.py +0 -0
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/__init__.py
RENAMED
|
@@ -5,7 +5,6 @@ from nonebot import on_command
|
|
|
5
5
|
from nonebot.params import CommandArg, Arg
|
|
6
6
|
from nonebot.adapters.onebot.v11.message import Message as V11Msg
|
|
7
7
|
from nonebot.adapters.onebot.v11.message import MessageSegment as V11Seg
|
|
8
|
-
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN
|
|
9
8
|
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
|
|
10
9
|
from nonebot.adapters.onebot.v11.event import MessageEvent
|
|
11
10
|
from nonebot.matcher import Matcher
|
|
@@ -15,7 +14,6 @@ from sqlalchemy.exc import DBAPIError
|
|
|
15
14
|
from arclet.alconna import Alconna, Option, Args, CommandMeta, append
|
|
16
15
|
import os
|
|
17
16
|
import random
|
|
18
|
-
import json
|
|
19
17
|
from typing import (
|
|
20
18
|
Any,
|
|
21
19
|
Union,
|
|
@@ -41,11 +39,11 @@ from nonebot.internal.adapter import (
|
|
|
41
39
|
require("nonebot_plugin_datastore")
|
|
42
40
|
|
|
43
41
|
from .error import (
|
|
44
|
-
NoPictureException,
|
|
45
42
|
SimilarPictureException,
|
|
46
43
|
SameNameException,
|
|
47
44
|
) # noqa: E402, E501
|
|
48
|
-
from .config import Config
|
|
45
|
+
from .config import Config
|
|
46
|
+
from .config import WORDS
|
|
49
47
|
from .pic_sql import ( # noqa: E402
|
|
50
48
|
savepic,
|
|
51
49
|
rename,
|
|
@@ -53,28 +51,17 @@ from .pic_sql import ( # noqa: E402
|
|
|
53
51
|
regexp_pic,
|
|
54
52
|
listpic,
|
|
55
53
|
)
|
|
56
|
-
from .rule import PIC_AMDIN
|
|
54
|
+
from .rule import PIC_AMDIN
|
|
55
|
+
from .rule import BLACK_GROUP
|
|
56
|
+
from .rule import GROUP_ADMIN
|
|
57
57
|
from .ext_listener import pic_listen # noqa: E402, F401
|
|
58
58
|
from .picture import write_pic, load_pic # noqa: E402
|
|
59
59
|
from .ai_utils import img2vec
|
|
60
|
-
from .randpic import
|
|
60
|
+
from .randpic import url_to_image
|
|
61
61
|
from .countpic import cpic
|
|
62
|
+
from .mvpic import INVALID_FILENAME_CHARACTERS
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
def url_to_image(url: str):
|
|
65
|
-
if url.startswith("http"):
|
|
66
|
-
return V11Seg.image(url)
|
|
67
|
-
return V11Seg.image(Path(url))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
words = {}
|
|
71
|
-
for root, _, files in os.walk("words"):
|
|
72
|
-
for file in files:
|
|
73
|
-
if not file.endswith(".json"):
|
|
74
|
-
continue
|
|
75
|
-
with open(os.path.join(root, file), "r", encoding="utf-8") as f:
|
|
76
|
-
words.update(json.load(f))
|
|
77
|
-
|
|
78
65
|
__plugin_meta__ = PluginMetadata(
|
|
79
66
|
name="Savepic",
|
|
80
67
|
description="表情包保存",
|
|
@@ -89,7 +76,6 @@ __plugin_meta__ = PluginMetadata(
|
|
|
89
76
|
type="application",
|
|
90
77
|
supported_adapters=["~onebot.v11"],
|
|
91
78
|
)
|
|
92
|
-
INVALID_FILENAME_CHARACTERS = r'\/:*?"<>|'
|
|
93
79
|
|
|
94
80
|
p_config = get_plugin_config(Config)
|
|
95
81
|
repic = on_command("repic", priority=5, permission=BLACK_GROUP)
|
|
@@ -102,13 +88,6 @@ a_spic = Alconna(
|
|
|
102
88
|
Args.filename[str],
|
|
103
89
|
meta=CommandMeta(description="保存图片,默认保存到本群"),
|
|
104
90
|
)
|
|
105
|
-
s_mvpic = on_command("mvpic", priority=5, permission=BLACK_GROUP)
|
|
106
|
-
a_mvpic = Alconna(
|
|
107
|
-
"/mvpic",
|
|
108
|
-
Option("-l", args=Args.filename[str], help_text="本地图片", action=append),
|
|
109
|
-
Option("-g", args=Args.filename[str], help_text="全局图片", action=append),
|
|
110
|
-
meta=CommandMeta(description="重命名图片,按照参数先后判断"),
|
|
111
|
-
)
|
|
112
91
|
s_simpic = on_command("simpic", priority=5, permission=BLACK_GROUP)
|
|
113
92
|
s_listpic = on_command("listpic", priority=5, permission=BLACK_GROUP)
|
|
114
93
|
|
|
@@ -175,11 +154,11 @@ async def _(bot: Bot, event, args: V11Msg = CommandArg()):
|
|
|
175
154
|
await bot.send(event, V11Msg([pic.name, url_to_image(pic.url)]))
|
|
176
155
|
except DBAPIError as ex:
|
|
177
156
|
await repic.finish(
|
|
178
|
-
f'{random.choice(
|
|
157
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex.orig}'
|
|
179
158
|
)
|
|
180
159
|
except Exception as ex:
|
|
181
160
|
await repic.finish(
|
|
182
|
-
f'{random.choice(
|
|
161
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
183
162
|
)
|
|
184
163
|
|
|
185
164
|
|
|
@@ -194,7 +173,7 @@ async def _(bot: Bot, event, args: V11Msg = CommandArg()):
|
|
|
194
173
|
pages = int(pages)
|
|
195
174
|
except Exception as ex:
|
|
196
175
|
await repic.finish(
|
|
197
|
-
f'{random.choice(
|
|
176
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
198
177
|
)
|
|
199
178
|
|
|
200
179
|
group_id = (
|
|
@@ -208,11 +187,11 @@ async def _(bot: Bot, event, args: V11Msg = CommandArg()):
|
|
|
208
187
|
await bot.send(event, "\n".join(pic))
|
|
209
188
|
except DBAPIError as ex:
|
|
210
189
|
await repic.finish(
|
|
211
|
-
f'{random.choice(
|
|
190
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex.orig}'
|
|
212
191
|
)
|
|
213
192
|
except Exception as ex:
|
|
214
193
|
await repic.finish(
|
|
215
|
-
f'{random.choice(
|
|
194
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
216
195
|
)
|
|
217
196
|
|
|
218
197
|
|
|
@@ -248,7 +227,7 @@ async def _(
|
|
|
248
227
|
if command.d:
|
|
249
228
|
if not (await PIC_AMDIN(bot, event) or await GROUP_ADMIN(bot, event)):
|
|
250
229
|
await spic.finish(
|
|
251
|
-
random.choice(
|
|
230
|
+
random.choice(WORDS.get("permission denied", ["没有权限"]))
|
|
252
231
|
)
|
|
253
232
|
try:
|
|
254
233
|
await delete(filename, state["savepiv_group"])
|
|
@@ -263,11 +242,11 @@ async def _(
|
|
|
263
242
|
matcher.set_arg("picture", picture)
|
|
264
243
|
|
|
265
244
|
|
|
266
|
-
@got_random_prompt(spic, "picture",
|
|
245
|
+
@got_random_prompt(spic, "picture", WORDS.get("wait for image", ["图呢"]))
|
|
267
246
|
async def _(state: T_State, picture: V11Msg = Arg()):
|
|
268
247
|
picture = picture.get("image")
|
|
269
248
|
if not picture:
|
|
270
|
-
await spic.finish(random.choice(
|
|
249
|
+
await spic.finish(random.choice(WORDS.get("not image", ["6,这也不是图啊"])))
|
|
271
250
|
|
|
272
251
|
try:
|
|
273
252
|
dir = await write_pic(picture[0].data["url"], p_config.savepic_dir)
|
|
@@ -284,7 +263,7 @@ async def _(state: T_State, picture: V11Msg = Arg()):
|
|
|
284
263
|
except SameNameException:
|
|
285
264
|
os.remove(dir)
|
|
286
265
|
await spic.finish(
|
|
287
|
-
random.choice(
|
|
266
|
+
random.choice(WORDS.get("name has been taken", ["文件名重复"]))
|
|
288
267
|
)
|
|
289
268
|
except SimilarPictureException as ex:
|
|
290
269
|
os.remove(dir)
|
|
@@ -292,13 +271,13 @@ async def _(state: T_State, picture: V11Msg = Arg()):
|
|
|
292
271
|
image = await load_pic(ex.url)
|
|
293
272
|
except Exception as exc:
|
|
294
273
|
await spic.finish(
|
|
295
|
-
f'{random.choice(
|
|
274
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{exc}'
|
|
296
275
|
)
|
|
297
276
|
|
|
298
277
|
await spic.finish(
|
|
299
278
|
V11Msg(
|
|
300
279
|
[
|
|
301
|
-
random.choice(
|
|
280
|
+
random.choice(WORDS.get("similar picture", ["存在相似图片"])),
|
|
302
281
|
"\n\n" + ex.name,
|
|
303
282
|
f"\n(相似度:{'%.4g' % (min(ex.similarity * 100, 100.0))}%)\n",
|
|
304
283
|
V11Seg.image(file=image),
|
|
@@ -307,70 +286,13 @@ async def _(state: T_State, picture: V11Msg = Arg()):
|
|
|
307
286
|
)
|
|
308
287
|
except Exception as ex:
|
|
309
288
|
os.remove(dir)
|
|
310
|
-
await spic.finish(f'{random.choice(
|
|
289
|
+
await spic.finish(f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}')
|
|
311
290
|
await spic.send(
|
|
312
|
-
random.choice(
|
|
291
|
+
random.choice(WORDS.get("save succeed", ["保存成功"]))
|
|
313
292
|
+ state["savepiv_warning"]
|
|
314
293
|
)
|
|
315
294
|
|
|
316
295
|
|
|
317
|
-
@s_mvpic.handle()
|
|
318
|
-
async def _(
|
|
319
|
-
bot: Bot,
|
|
320
|
-
event: GroupMessageEvent,
|
|
321
|
-
):
|
|
322
|
-
if not (await PIC_AMDIN(bot, event) or await GROUP_ADMIN(bot, event)):
|
|
323
|
-
await spic.finish(random.choice(words.get("permission denied", ["没有权限"])))
|
|
324
|
-
|
|
325
|
-
cmd = a_mvpic.parse(event.message.extract_plain_text())
|
|
326
|
-
if not cmd.matched:
|
|
327
|
-
await s_mvpic.finish(str(cmd.error_info) + "\n\n" + a_mvpic.get_help())
|
|
328
|
-
options = cmd.options
|
|
329
|
-
if not options:
|
|
330
|
-
await s_mvpic.finish("文件名呢?" + "\n\n" + a_mvpic.get_help())
|
|
331
|
-
|
|
332
|
-
sg = "globe" if list(options.keys())[0] == "g" else f"qq_group:{event.group_id}"
|
|
333
|
-
if len(options["g" if sg == "globe" else "l"].args.get("filename", [])) >= 2:
|
|
334
|
-
dg = sg
|
|
335
|
-
else:
|
|
336
|
-
dg = "globe" if sg != "globe" else f"qq_group:{event.group_id}"
|
|
337
|
-
if ("g" if dg == "globe" else "l") not in options:
|
|
338
|
-
await s_mvpic.finish("至多只有一个文件名哦?" + "\n\n" + a_mvpic.get_help())
|
|
339
|
-
|
|
340
|
-
if (not await PIC_AMDIN(bot, event)) and await GROUP_ADMIN(bot, event):
|
|
341
|
-
if sg == "globe":
|
|
342
|
-
await spic.finish("管理员不能改全局名称哦~")
|
|
343
|
-
if dg == "globe":
|
|
344
|
-
await spic.finish("管理员不能改全局名称哦~")
|
|
345
|
-
|
|
346
|
-
sname = options["g" if sg == "globe" else "l"].args["filename"][0]
|
|
347
|
-
dname = options["g" if dg == "globe" else "l"].args["filename"][
|
|
348
|
-
1 if sg == dg else 0
|
|
349
|
-
]
|
|
350
|
-
for c in INVALID_FILENAME_CHARACTERS:
|
|
351
|
-
sname = sname.replace(c, "-")
|
|
352
|
-
dname = dname.replace(c, "-")
|
|
353
|
-
if not sname.endswith((".jpg", ".png", ".gif")):
|
|
354
|
-
sname += ".jpg"
|
|
355
|
-
if not dname.endswith((".jpg", ".png", ".gif")):
|
|
356
|
-
dname += ".jpg"
|
|
357
|
-
|
|
358
|
-
try:
|
|
359
|
-
await rename(sname, dname, sg, dg)
|
|
360
|
-
except NoPictureException as ex:
|
|
361
|
-
await spic.finish(
|
|
362
|
-
random.choice(words.get("not found", [ex.name + " 没有找到哦"]))
|
|
363
|
-
+ f"\n{ex.name} 没有找到哦"
|
|
364
|
-
)
|
|
365
|
-
except SameNameException:
|
|
366
|
-
await spic.finish(
|
|
367
|
-
random.choice(words.get("name has been taken", ["文件名重复"]))
|
|
368
|
-
)
|
|
369
|
-
except Exception as ex:
|
|
370
|
-
await spic.finish(f'{random.choice(words.get("error", ["出错了喵~"]))}\n\n{ex}')
|
|
371
|
-
await spic.finish(random.choice(words.get("rename succeed", ["图片已重命名"])))
|
|
372
|
-
|
|
373
|
-
|
|
374
296
|
@s_simpic.handle()
|
|
375
297
|
async def _(bot: Bot, event: MessageEvent, args: V11Msg = CommandArg()):
|
|
376
298
|
if True:
|
|
@@ -380,7 +302,7 @@ async def _(bot: Bot, event: MessageEvent, args: V11Msg = CommandArg()):
|
|
|
380
302
|
if not picture:
|
|
381
303
|
await s_simpic.finish(
|
|
382
304
|
random.choice(
|
|
383
|
-
|
|
305
|
+
WORDS.get("missing image reference", ["没找到引用消息中的图片"])
|
|
384
306
|
)
|
|
385
307
|
)
|
|
386
308
|
vec = img2vec(await load_pic(picture[0].data["url"]))
|
|
@@ -411,8 +333,8 @@ async def _(bot: Bot, event: MessageEvent, args: V11Msg = CommandArg()):
|
|
|
411
333
|
),
|
|
412
334
|
)
|
|
413
335
|
else:
|
|
414
|
-
await s_simpic.send(random.choice(
|
|
336
|
+
await s_simpic.send(random.choice(WORDS.get("not found", ["Nope."])))
|
|
415
337
|
except Exception as ex:
|
|
416
338
|
await s_simpic.finish(
|
|
417
|
-
f'{random.choice(
|
|
339
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
418
340
|
)
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/config.py
RENAMED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
1
3
|
from pydantic import BaseModel
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
WORDS = {}
|
|
7
|
+
for root, _, files in os.walk("words"):
|
|
8
|
+
for file in files:
|
|
9
|
+
if not file.endswith(".json"):
|
|
10
|
+
continue
|
|
11
|
+
with open(os.path.join(root, file), "r", encoding="utf-8") as f:
|
|
12
|
+
WORDS.update(json.load(f))
|
|
3
13
|
|
|
4
14
|
|
|
5
15
|
class Config(BaseModel):
|
|
@@ -23,3 +33,6 @@ class Config(BaseModel):
|
|
|
23
33
|
|
|
24
34
|
embedding_sqlurl: str
|
|
25
35
|
black_group: list[str]
|
|
36
|
+
|
|
37
|
+
notfound_with_jpg: bool = True
|
|
38
|
+
""" randpic 的时候,尝试带 .jpg 再度检索向量 """
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import re
|
|
3
|
+
from nonebot import on_command
|
|
4
|
+
from nonebot.params import CommandArg
|
|
5
|
+
from nonebot.internal.adapter import Bot
|
|
6
|
+
from nonebot.adapters.onebot.v11.event import GroupMessageEvent as V11GME
|
|
7
|
+
from .rule import BLACK_GROUP
|
|
8
|
+
from .rule import PIC_AMDIN
|
|
9
|
+
from .rule import GROUP_ADMIN
|
|
10
|
+
from .config import WORDS
|
|
11
|
+
from .pic_sql import rename
|
|
12
|
+
from .error import NoPictureException
|
|
13
|
+
from .error import SameNameException
|
|
14
|
+
|
|
15
|
+
s_mvpic = on_command("mvpic", priority=5, permission=BLACK_GROUP)
|
|
16
|
+
INVALID_FILENAME_CHARACTERS = r'\/:*?"<>|'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# mvpic -l name -g name
|
|
20
|
+
# mvpic -lg name name
|
|
21
|
+
# mvpic -gl name name
|
|
22
|
+
# mvpic -l -g name
|
|
23
|
+
# mvpic -g -l name
|
|
24
|
+
# mvpic -gl name
|
|
25
|
+
# mvpic -lg name
|
|
26
|
+
# mvpic name name
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@s_mvpic.handle()
|
|
30
|
+
async def _(bot: Bot, event: V11GME, args=CommandArg()):
|
|
31
|
+
if not (await PIC_AMDIN(bot, event) or await GROUP_ADMIN(bot, event)):
|
|
32
|
+
await s_mvpic.finish(
|
|
33
|
+
random.choice(WORDS.get("permission denied", ["没有权限"]))
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
cmd = args.extract_plain_text().strip()
|
|
37
|
+
name = []
|
|
38
|
+
options = []
|
|
39
|
+
|
|
40
|
+
def parser():
|
|
41
|
+
pos = 0
|
|
42
|
+
nonlocal cmd, name, options
|
|
43
|
+
|
|
44
|
+
def _str(t: str) -> str:
|
|
45
|
+
nonlocal pos, cmd
|
|
46
|
+
|
|
47
|
+
result = ""
|
|
48
|
+
pos += 1
|
|
49
|
+
while pos < len(cmd):
|
|
50
|
+
if cmd[pos] == t:
|
|
51
|
+
break
|
|
52
|
+
if not t and not cmd[pos].strip():
|
|
53
|
+
break
|
|
54
|
+
|
|
55
|
+
if cmd[pos] == "\\":
|
|
56
|
+
pos += 1
|
|
57
|
+
if pos >= len(cmd):
|
|
58
|
+
result += "\\"
|
|
59
|
+
break
|
|
60
|
+
elif cmd[pos] == "'":
|
|
61
|
+
result += "'"
|
|
62
|
+
elif cmd[pos] == '"':
|
|
63
|
+
result += '"'
|
|
64
|
+
elif cmd[pos] == "t":
|
|
65
|
+
result += "\t"
|
|
66
|
+
elif cmd[pos] == "n":
|
|
67
|
+
result += "\n"
|
|
68
|
+
elif cmd[pos] == "r":
|
|
69
|
+
result += "\r"
|
|
70
|
+
elif cmd[pos] == "\\":
|
|
71
|
+
result += "\\"
|
|
72
|
+
else:
|
|
73
|
+
result += "\\"
|
|
74
|
+
pos -= 1
|
|
75
|
+
else:
|
|
76
|
+
result += cmd[pos]
|
|
77
|
+
pos += 1
|
|
78
|
+
pos += 1
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
def _options() -> list[str]:
|
|
82
|
+
nonlocal pos, cmd
|
|
83
|
+
|
|
84
|
+
pos += 1
|
|
85
|
+
result = []
|
|
86
|
+
while pos < len(cmd) and cmd[pos].strip():
|
|
87
|
+
result.append(cmd[pos])
|
|
88
|
+
pos += 1
|
|
89
|
+
return result
|
|
90
|
+
|
|
91
|
+
while pos < len(cmd):
|
|
92
|
+
if cmd[pos] == "'":
|
|
93
|
+
name.append(_str("'"))
|
|
94
|
+
elif not cmd[pos].strip():
|
|
95
|
+
pos += 1
|
|
96
|
+
elif cmd[pos] == "-":
|
|
97
|
+
options.extend(_options())
|
|
98
|
+
elif cmd[pos] == '"':
|
|
99
|
+
name.append(_str('"'))
|
|
100
|
+
else:
|
|
101
|
+
pos -= 1
|
|
102
|
+
name.append(_str(""))
|
|
103
|
+
|
|
104
|
+
parser()
|
|
105
|
+
if not name:
|
|
106
|
+
await s_mvpic.finish("文件名呢?")
|
|
107
|
+
if not options:
|
|
108
|
+
options = ["l"]
|
|
109
|
+
|
|
110
|
+
if (not await PIC_AMDIN(bot, event)) and await GROUP_ADMIN(bot, event):
|
|
111
|
+
if "g" in options:
|
|
112
|
+
await s_mvpic.finish("管理员不能改全局名称哦~")
|
|
113
|
+
|
|
114
|
+
sname = name[0]
|
|
115
|
+
dname = name[1] if len(name) > 1 else sname
|
|
116
|
+
for c in INVALID_FILENAME_CHARACTERS:
|
|
117
|
+
sname = sname.replace(c, "-")
|
|
118
|
+
dname = dname.replace(c, "-")
|
|
119
|
+
if not sname.endswith((".jpg", ".png", ".gif")):
|
|
120
|
+
sname += ".jpg"
|
|
121
|
+
if not dname.endswith((".jpg", ".png", ".gif")):
|
|
122
|
+
dname += ".jpg"
|
|
123
|
+
|
|
124
|
+
sg = "globe" if options[0] == "g" else f"qq_group:{event.group_id}"
|
|
125
|
+
dg = options[1] if len(options) > 1 else options[0]
|
|
126
|
+
dg = "globe" if dg == "g" else f"qq_group:{event.group_id}"
|
|
127
|
+
|
|
128
|
+
if sname == dname and sg == dg:
|
|
129
|
+
await s_mvpic.finish("嗯,什么都没有变化嘛。")
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
await rename(sname, dname, sg, dg)
|
|
133
|
+
except NoPictureException as ex:
|
|
134
|
+
await s_mvpic.finish(
|
|
135
|
+
random.choice(WORDS.get("not found", [ex.name + " 没有找到哦"]))
|
|
136
|
+
+ f"\n{ex.name} 没有找到哦"
|
|
137
|
+
)
|
|
138
|
+
except SameNameException:
|
|
139
|
+
await s_mvpic.finish(
|
|
140
|
+
random.choice(WORDS.get("name has been taken", ["文件名重复"]))
|
|
141
|
+
)
|
|
142
|
+
except Exception as ex:
|
|
143
|
+
await s_mvpic.finish(
|
|
144
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
145
|
+
)
|
|
146
|
+
await s_mvpic.finish(random.choice(WORDS.get("rename succeed", ["图片已重命名"])))
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/pic_sql.py
RENAMED
|
@@ -30,14 +30,31 @@ def AsyncDatabase():
|
|
|
30
30
|
return _async_database
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
async def update_vec(pic: PicData):
|
|
34
|
+
if pic is None:
|
|
35
|
+
return
|
|
36
|
+
if not pic.u_vec_text:
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
async with AsyncSession(_async_database) as db_session:
|
|
40
|
+
if pic.u_vec_text:
|
|
41
|
+
pic.u_vec_text = False
|
|
42
|
+
await _async_embedding_database.execute(
|
|
43
|
+
"UPDATE savepic_word2vec SET embedding = $1 WHERE id = $2",
|
|
44
|
+
str(word2vec(pic.name)),
|
|
45
|
+
pic.id,
|
|
46
|
+
)
|
|
47
|
+
db_session.merge(pic)
|
|
48
|
+
db_session.commit()
|
|
49
|
+
|
|
50
|
+
|
|
33
51
|
async def select_pic(filename: str, group: str):
|
|
34
52
|
async with AsyncSession(_async_database) as db_session:
|
|
35
|
-
pic
|
|
53
|
+
if pic := await db_session.scalar(
|
|
36
54
|
select(PicData)
|
|
37
55
|
.where(PicData.name == filename)
|
|
38
56
|
.where(PicData.group == group)
|
|
39
|
-
)
|
|
40
|
-
if pic:
|
|
57
|
+
):
|
|
41
58
|
await update_vec(pic)
|
|
42
59
|
return pic
|
|
43
60
|
return await db_session.scalar(
|
|
@@ -97,19 +114,6 @@ async def savepic(
|
|
|
97
114
|
if despic:
|
|
98
115
|
raise SameNameException(despic.name)
|
|
99
116
|
|
|
100
|
-
# if not collision_allow:
|
|
101
|
-
# ret = _pincone_index.query(img_vec, top_k=25)["matches"]
|
|
102
|
-
# for i in ret:
|
|
103
|
-
# if i["score"] and i["score"] < 0.98:
|
|
104
|
-
# break
|
|
105
|
-
# despic = await db_session.scalar(
|
|
106
|
-
# select(PicData)
|
|
107
|
-
# .where(PicData.id == int(ret[0]["id"]))
|
|
108
|
-
# .where(sa.or_(PicData.group == group_id, PicData.group == "globe"))
|
|
109
|
-
# )
|
|
110
|
-
# if despic:
|
|
111
|
-
# raise SimilarPictureException(despic.name, i["score"], despic.url)
|
|
112
|
-
|
|
113
117
|
empty = await db_session.scalar(select(PicData).where(PicData.name == ""))
|
|
114
118
|
if empty:
|
|
115
119
|
pic.id = empty.id
|
|
@@ -118,7 +122,6 @@ async def savepic(
|
|
|
118
122
|
db_session.add(pic)
|
|
119
123
|
await db_session.flush()
|
|
120
124
|
|
|
121
|
-
# _pincone_index.upsert([(str(pic.id), img_vec)])
|
|
122
125
|
await _async_embedding_database.execute(
|
|
123
126
|
(
|
|
124
127
|
"INSERT INTO savepic_word2vec (id, embedding) VALUES ($1, $2) "
|
|
@@ -145,9 +148,9 @@ async def rename(ori: str, des: str, s_group: str, d_group: str):
|
|
|
145
148
|
)
|
|
146
149
|
if despic:
|
|
147
150
|
raise SameNameException(despic.name)
|
|
151
|
+
|
|
148
152
|
pic.name = des
|
|
149
153
|
pic.group = d_group
|
|
150
|
-
|
|
151
154
|
pic.u_vec_text = False
|
|
152
155
|
await _async_embedding_database.execute(
|
|
153
156
|
"UPDATE savepic_word2vec SET embedding = $1 WHERE id = $2",
|
|
@@ -218,6 +221,7 @@ async def randpic(
|
|
|
218
221
|
):
|
|
219
222
|
await update_vec(pic)
|
|
220
223
|
return pic, ""
|
|
224
|
+
|
|
221
225
|
if not vector:
|
|
222
226
|
return None, ""
|
|
223
227
|
|
|
@@ -237,6 +241,25 @@ async def randpic(
|
|
|
237
241
|
.order_by(sa.func.random())
|
|
238
242
|
):
|
|
239
243
|
return pic, "(语义向量相似度检索)"
|
|
244
|
+
|
|
245
|
+
if p_config.notfound_with_jpg:
|
|
246
|
+
datas = await _async_embedding_database.fetch(
|
|
247
|
+
(
|
|
248
|
+
"SELECT id FROM savepic_word2vec "
|
|
249
|
+
"WHERE embedding IS NOT NULL and embedding <=> $1 <= 0.45 "
|
|
250
|
+
"ORDER BY embedding <#> $1 LIMIT 8;"
|
|
251
|
+
),
|
|
252
|
+
str(word2vec(name + ".jpg")),
|
|
253
|
+
)
|
|
254
|
+
if pic := await db_session.scalar(
|
|
255
|
+
select(PicData)
|
|
256
|
+
.where(sa.or_(PicData.group == group, PicData.group == "globe"))
|
|
257
|
+
.where(PicData.id.in_([i["id"] for i in datas]))
|
|
258
|
+
.where(PicData.name != "")
|
|
259
|
+
.order_by(sa.func.random())
|
|
260
|
+
):
|
|
261
|
+
return pic, "(语义向量相似度检索)"
|
|
262
|
+
|
|
240
263
|
return None, False
|
|
241
264
|
|
|
242
265
|
|
|
@@ -258,29 +281,6 @@ async def countpic(reg: str, group: str = "globe") -> int:
|
|
|
258
281
|
return 0
|
|
259
282
|
|
|
260
283
|
|
|
261
|
-
async def update_vec(pic: PicData):
|
|
262
|
-
if not pic:
|
|
263
|
-
return
|
|
264
|
-
if not pic.u_vec_text: # and not pic.u_vec_img:
|
|
265
|
-
return
|
|
266
|
-
if pic.u_vec_text:
|
|
267
|
-
pic.u_vec_text = False
|
|
268
|
-
await _async_embedding_database.execute(
|
|
269
|
-
"UPDATE savepic_word2vec SET embedding = $1 WHERE id = $2",
|
|
270
|
-
str(word2vec(pic.name)),
|
|
271
|
-
pic.id,
|
|
272
|
-
)
|
|
273
|
-
# if pic.u_vec_img:
|
|
274
|
-
# pic.u_vec_img = False
|
|
275
|
-
# _pincone_index.upsert(
|
|
276
|
-
# [(str(pic.id), file2vec(pathlib.Path(pic.url), pic.name))]
|
|
277
|
-
# )
|
|
278
|
-
async with AsyncSession(_async_database) as db_session:
|
|
279
|
-
db_session.merge(pic)
|
|
280
|
-
await db_session.flush()
|
|
281
|
-
db_session.commit()
|
|
282
|
-
|
|
283
|
-
|
|
284
284
|
async def listpic(reg: str, group: str = "globe", pages: int = 0) -> list[str]:
|
|
285
285
|
reg = reg.strip()
|
|
286
286
|
if not reg:
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/rule.py
RENAMED
|
@@ -7,6 +7,8 @@ from nonebot.adapters import Bot, Event
|
|
|
7
7
|
from nonebot.internal.permission import Permission
|
|
8
8
|
from nonebot.adapters.onebot.v11.event import GroupMessageEvent as V11G
|
|
9
9
|
from .config import Config
|
|
10
|
+
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
plugin_config = get_plugin_config(Config)
|
|
12
14
|
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ai_utils.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/countpic.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/error.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ext_listener.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/picture.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/randpic.py
RENAMED
|
File without changes
|