nonebot-plugin-savepic 0.2.6__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.6 → nonebot_plugin_savepic-0.2.7}/PKG-INFO +1 -1
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/config.py +3 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/mvpic.py +9 -8
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/pic_sql.py +41 -41
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/pyproject.toml +1 -1
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/LICENSE +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/README.md +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/__init__.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ai_utils.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/countpic.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/error.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ext_listener.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/model.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/networks/__init__.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/networks/resnet_big.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/picture.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/randpic.py +0 -0
- {nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/rule.py +0 -0
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/mvpic.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import random
|
|
2
2
|
import re
|
|
3
3
|
from nonebot import on_command
|
|
4
|
+
from nonebot.params import CommandArg
|
|
4
5
|
from nonebot.internal.adapter import Bot
|
|
5
6
|
from nonebot.adapters.onebot.v11.event import GroupMessageEvent as V11GME
|
|
6
7
|
from .rule import BLACK_GROUP
|
|
@@ -26,16 +27,13 @@ INVALID_FILENAME_CHARACTERS = r'\/:*?"<>|'
|
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
@s_mvpic.handle()
|
|
29
|
-
async def _(
|
|
30
|
-
bot: Bot,
|
|
31
|
-
event: V11GME,
|
|
32
|
-
):
|
|
30
|
+
async def _(bot: Bot, event: V11GME, args=CommandArg()):
|
|
33
31
|
if not (await PIC_AMDIN(bot, event) or await GROUP_ADMIN(bot, event)):
|
|
34
32
|
await s_mvpic.finish(
|
|
35
33
|
random.choice(WORDS.get("permission denied", ["没有权限"]))
|
|
36
34
|
)
|
|
37
35
|
|
|
38
|
-
cmd =
|
|
36
|
+
cmd = args.extract_plain_text().strip()
|
|
39
37
|
name = []
|
|
40
38
|
options = []
|
|
41
39
|
|
|
@@ -104,7 +102,6 @@ async def _(
|
|
|
104
102
|
name.append(_str(""))
|
|
105
103
|
|
|
106
104
|
parser()
|
|
107
|
-
|
|
108
105
|
if not name:
|
|
109
106
|
await s_mvpic.finish("文件名呢?")
|
|
110
107
|
if not options:
|
|
@@ -124,8 +121,12 @@ async def _(
|
|
|
124
121
|
if not dname.endswith((".jpg", ".png", ".gif")):
|
|
125
122
|
dname += ".jpg"
|
|
126
123
|
|
|
127
|
-
sg = options[0]
|
|
128
|
-
dg = options[1] if len(options) > 1 else
|
|
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("嗯,什么都没有变化嘛。")
|
|
129
130
|
|
|
130
131
|
try:
|
|
131
132
|
await rename(sname, dname, sg, dg)
|
{nonebot_plugin_savepic-0.2.6 → 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:
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/__init__.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ai_utils.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/countpic.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/error.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/ext_listener.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → 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.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/picture.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/randpic.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.6 → nonebot_plugin_savepic-0.2.7}/nonebot_plugin_savepic/rule.py
RENAMED
|
File without changes
|