nonebot-plugin-savepic 0.2.5__tar.gz → 0.2.6__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.6}/PKG-INFO +1 -1
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/__init__.py +23 -101
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/config.py +11 -1
- nonebot_plugin_savepic-0.2.6/nonebot_plugin_savepic/mvpic.py +145 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/rule.py +2 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/pyproject.toml +1 -1
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/LICENSE +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/README.md +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/ai_utils.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/countpic.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/error.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/ext_listener.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/model.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/networks/__init__.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/networks/resnet_big.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/pic_sql.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/picture.py +0 -0
- {nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/randpic.py +0 -0
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/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.6}/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):
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import re
|
|
3
|
+
from nonebot import on_command
|
|
4
|
+
from nonebot.internal.adapter import Bot
|
|
5
|
+
from nonebot.adapters.onebot.v11.event import GroupMessageEvent as V11GME
|
|
6
|
+
from .rule import BLACK_GROUP
|
|
7
|
+
from .rule import PIC_AMDIN
|
|
8
|
+
from .rule import GROUP_ADMIN
|
|
9
|
+
from .config import WORDS
|
|
10
|
+
from .pic_sql import rename
|
|
11
|
+
from .error import NoPictureException
|
|
12
|
+
from .error import SameNameException
|
|
13
|
+
|
|
14
|
+
s_mvpic = on_command("mvpic", priority=5, permission=BLACK_GROUP)
|
|
15
|
+
INVALID_FILENAME_CHARACTERS = r'\/:*?"<>|'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# mvpic -l name -g name
|
|
19
|
+
# mvpic -lg name name
|
|
20
|
+
# mvpic -gl name name
|
|
21
|
+
# mvpic -l -g name
|
|
22
|
+
# mvpic -g -l name
|
|
23
|
+
# mvpic -gl name
|
|
24
|
+
# mvpic -lg name
|
|
25
|
+
# mvpic name name
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@s_mvpic.handle()
|
|
29
|
+
async def _(
|
|
30
|
+
bot: Bot,
|
|
31
|
+
event: V11GME,
|
|
32
|
+
):
|
|
33
|
+
if not (await PIC_AMDIN(bot, event) or await GROUP_ADMIN(bot, event)):
|
|
34
|
+
await s_mvpic.finish(
|
|
35
|
+
random.choice(WORDS.get("permission denied", ["没有权限"]))
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
cmd = event.message.extract_plain_text().strip()
|
|
39
|
+
name = []
|
|
40
|
+
options = []
|
|
41
|
+
|
|
42
|
+
def parser():
|
|
43
|
+
pos = 0
|
|
44
|
+
nonlocal cmd, name, options
|
|
45
|
+
|
|
46
|
+
def _str(t: str) -> str:
|
|
47
|
+
nonlocal pos, cmd
|
|
48
|
+
|
|
49
|
+
result = ""
|
|
50
|
+
pos += 1
|
|
51
|
+
while pos < len(cmd):
|
|
52
|
+
if cmd[pos] == t:
|
|
53
|
+
break
|
|
54
|
+
if not t and not cmd[pos].strip():
|
|
55
|
+
break
|
|
56
|
+
|
|
57
|
+
if cmd[pos] == "\\":
|
|
58
|
+
pos += 1
|
|
59
|
+
if pos >= len(cmd):
|
|
60
|
+
result += "\\"
|
|
61
|
+
break
|
|
62
|
+
elif cmd[pos] == "'":
|
|
63
|
+
result += "'"
|
|
64
|
+
elif cmd[pos] == '"':
|
|
65
|
+
result += '"'
|
|
66
|
+
elif cmd[pos] == "t":
|
|
67
|
+
result += "\t"
|
|
68
|
+
elif cmd[pos] == "n":
|
|
69
|
+
result += "\n"
|
|
70
|
+
elif cmd[pos] == "r":
|
|
71
|
+
result += "\r"
|
|
72
|
+
elif cmd[pos] == "\\":
|
|
73
|
+
result += "\\"
|
|
74
|
+
else:
|
|
75
|
+
result += "\\"
|
|
76
|
+
pos -= 1
|
|
77
|
+
else:
|
|
78
|
+
result += cmd[pos]
|
|
79
|
+
pos += 1
|
|
80
|
+
pos += 1
|
|
81
|
+
return result
|
|
82
|
+
|
|
83
|
+
def _options() -> list[str]:
|
|
84
|
+
nonlocal pos, cmd
|
|
85
|
+
|
|
86
|
+
pos += 1
|
|
87
|
+
result = []
|
|
88
|
+
while pos < len(cmd) and cmd[pos].strip():
|
|
89
|
+
result.append(cmd[pos])
|
|
90
|
+
pos += 1
|
|
91
|
+
return result
|
|
92
|
+
|
|
93
|
+
while pos < len(cmd):
|
|
94
|
+
if cmd[pos] == "'":
|
|
95
|
+
name.append(_str("'"))
|
|
96
|
+
elif not cmd[pos].strip():
|
|
97
|
+
pos += 1
|
|
98
|
+
elif cmd[pos] == "-":
|
|
99
|
+
options.extend(_options())
|
|
100
|
+
elif cmd[pos] == '"':
|
|
101
|
+
name.append(_str('"'))
|
|
102
|
+
else:
|
|
103
|
+
pos -= 1
|
|
104
|
+
name.append(_str(""))
|
|
105
|
+
|
|
106
|
+
parser()
|
|
107
|
+
|
|
108
|
+
if not name:
|
|
109
|
+
await s_mvpic.finish("文件名呢?")
|
|
110
|
+
if not options:
|
|
111
|
+
options = ["l"]
|
|
112
|
+
|
|
113
|
+
if (not await PIC_AMDIN(bot, event)) and await GROUP_ADMIN(bot, event):
|
|
114
|
+
if "g" in options:
|
|
115
|
+
await s_mvpic.finish("管理员不能改全局名称哦~")
|
|
116
|
+
|
|
117
|
+
sname = name[0]
|
|
118
|
+
dname = name[1] if len(name) > 1 else sname
|
|
119
|
+
for c in INVALID_FILENAME_CHARACTERS:
|
|
120
|
+
sname = sname.replace(c, "-")
|
|
121
|
+
dname = dname.replace(c, "-")
|
|
122
|
+
if not sname.endswith((".jpg", ".png", ".gif")):
|
|
123
|
+
sname += ".jpg"
|
|
124
|
+
if not dname.endswith((".jpg", ".png", ".gif")):
|
|
125
|
+
dname += ".jpg"
|
|
126
|
+
|
|
127
|
+
sg = options[0]
|
|
128
|
+
dg = options[1] if len(options) > 1 else sg
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
await rename(sname, dname, sg, dg)
|
|
132
|
+
except NoPictureException as ex:
|
|
133
|
+
await s_mvpic.finish(
|
|
134
|
+
random.choice(WORDS.get("not found", [ex.name + " 没有找到哦"]))
|
|
135
|
+
+ f"\n{ex.name} 没有找到哦"
|
|
136
|
+
)
|
|
137
|
+
except SameNameException:
|
|
138
|
+
await s_mvpic.finish(
|
|
139
|
+
random.choice(WORDS.get("name has been taken", ["文件名重复"]))
|
|
140
|
+
)
|
|
141
|
+
except Exception as ex:
|
|
142
|
+
await s_mvpic.finish(
|
|
143
|
+
f'{random.choice(WORDS.get("error", ["出错了喵~"]))}\n\n{ex}'
|
|
144
|
+
)
|
|
145
|
+
await s_mvpic.finish(random.choice(WORDS.get("rename succeed", ["图片已重命名"])))
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/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.6}/nonebot_plugin_savepic/ai_utils.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/countpic.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/error.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/ext_listener.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/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.6}/nonebot_plugin_savepic/pic_sql.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/picture.py
RENAMED
|
File without changes
|
{nonebot_plugin_savepic-0.2.5 → nonebot_plugin_savepic-0.2.6}/nonebot_plugin_savepic/randpic.py
RENAMED
|
File without changes
|