mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
修复修改图库配置重载后上传图片时提示的图库与配置不符
This commit is contained in:
parent
7d86ff057c
commit
26db0fad85
@ -334,6 +334,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
|
||||
### 2023/5/23
|
||||
|
||||
* 修复群聊数据无法初始化
|
||||
* 修复修改图库配置重载后上传图片时提示的图库与配置不符
|
||||
|
||||
### 2023/5/22
|
||||
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
from configs.path_config import IMAGE_PATH, TEMP_PATH
|
||||
from utils.message_builder import image
|
||||
from services.log import logger
|
||||
import os
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message, MessageEvent
|
||||
from nonebot.params import Arg, ArgStr, CommandArg
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent, GroupMessageEvent, Message
|
||||
from utils.utils import is_number, cn2py
|
||||
|
||||
from configs.config import Config
|
||||
from nonebot.params import CommandArg, Arg
|
||||
import os
|
||||
from configs.path_config import IMAGE_PATH, TEMP_PATH
|
||||
from services.log import logger
|
||||
from utils.message_builder import image
|
||||
from utils.utils import cn2py, is_number
|
||||
|
||||
__zx_plugin_name__ = "删除图片 [Admin]"
|
||||
__plugin_usage__ = """
|
||||
@ -36,9 +38,10 @@ _path = IMAGE_PATH / "image_management"
|
||||
|
||||
@delete_img.handle()
|
||||
async def _(state: T_State, arg: Message = CommandArg()):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
args = arg.extract_plain_text().strip().split()
|
||||
if args:
|
||||
if args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if args[0] in image_dir_list:
|
||||
state["path"] = args[0]
|
||||
if len(args) > 1 and is_number(args[1]):
|
||||
state["id"] = args[1]
|
||||
@ -49,16 +52,17 @@ async def _(state: T_State, arg: Message = CommandArg()):
|
||||
async def arg_handle(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
path: str = Arg("path"),
|
||||
img_id: str = Arg("id"),
|
||||
path_: str = ArgStr("path"),
|
||||
img_id: str = ArgStr("id"),
|
||||
):
|
||||
if path in ["取消", "算了"] or img_id in ["取消", "算了"]:
|
||||
if path_ in ["取消", "算了"] or img_id in ["取消", "算了"]:
|
||||
await delete_img.finish("已取消操作...")
|
||||
if path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
if path_ not in image_dir_list:
|
||||
await delete_img.reject_arg("path", "此目录不正确,请重新输入目录!")
|
||||
if not is_number(img_id):
|
||||
await delete_img.reject_arg("id", "id不正确!请重新输入数字...")
|
||||
path = _path / cn2py(path)
|
||||
path = _path / cn2py(path_)
|
||||
if not path.exists() and (path.parent.parent / cn2py(state["path"])).exists():
|
||||
path = path.parent.parent / cn2py(state["path"])
|
||||
max_id = len(os.listdir(path)) - 1
|
||||
@ -87,6 +91,10 @@ async def arg_handle(
|
||||
f" -> id: {img_id} 删除成功"
|
||||
)
|
||||
await delete_img.finish(
|
||||
f"id: {img_id} 删除成功" + image(TEMP_PATH / f"{event.user_id}_delete.jpg",), at_sender=True
|
||||
f"id: {img_id} 删除成功"
|
||||
+ image(
|
||||
TEMP_PATH / f"{event.user_id}_delete.jpg",
|
||||
),
|
||||
at_sender=True,
|
||||
)
|
||||
await delete_img.finish(f"id: {img_id} 删除失败!")
|
||||
|
||||
@ -35,13 +35,14 @@ _path = IMAGE_PATH / "image_management"
|
||||
|
||||
@move_img.handle()
|
||||
async def _(state: T_State, arg: Message = CommandArg()):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
args = arg.extract_plain_text().strip().split()
|
||||
if args:
|
||||
if n := len(args):
|
||||
if args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if args[0] in image_dir_list:
|
||||
state["source_path"] = args[0]
|
||||
if n > 1:
|
||||
if args[1] in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if args[1] in image_dir_list:
|
||||
state["destination_path"] = args[1]
|
||||
if n > 2 and is_number(args[2]):
|
||||
state["id"] = args[2]
|
||||
@ -52,24 +53,25 @@ async def _(state: T_State, arg: Message = CommandArg()):
|
||||
@move_img.got("id", prompt="要移动的图片id是?")
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
source_path: str = ArgStr("source_path"),
|
||||
destination_path: str = ArgStr("destination_path"),
|
||||
source_path_: str = ArgStr("source_path"),
|
||||
destination_path_: str = ArgStr("destination_path"),
|
||||
img_id: str = ArgStr("id"),
|
||||
):
|
||||
if (
|
||||
source_path in ["取消", "算了"]
|
||||
source_path_ in ["取消", "算了"]
|
||||
or img_id in ["取消", "算了"]
|
||||
or destination_path in ["取消", "算了"]
|
||||
or destination_path_ in ["取消", "算了"]
|
||||
):
|
||||
await move_img.finish("已取消操作...")
|
||||
if source_path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
if source_path_ not in image_dir_list:
|
||||
await move_img.reject_arg("source_path", "移除目录不正确,请重新输入!")
|
||||
if destination_path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if destination_path_ not in image_dir_list:
|
||||
await move_img.reject_arg("destination_path", "移入目录不正确,请重新输入!")
|
||||
if not is_number(img_id):
|
||||
await move_img.reject_arg("id", "id不正确!请重新输入数字...")
|
||||
source_path = _path / cn2py(source_path)
|
||||
destination_path = _path / cn2py(destination_path)
|
||||
source_path = _path / cn2py(source_path_)
|
||||
destination_path = _path / cn2py(destination_path_)
|
||||
if not source_path.exists():
|
||||
if (source_path.parent.parent / cn2py(source_path.name)).exists():
|
||||
source_path = source_path.parent.parent / cn2py(source_path.name)
|
||||
|
||||
@ -51,15 +51,16 @@ _path = IMAGE_PATH / "image_management"
|
||||
|
||||
@send_img.handle()
|
||||
async def _(event: MessageEvent):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
msg = get_message_text(event.json()).split()
|
||||
gallery = msg[0]
|
||||
if gallery not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if gallery not in image_dir_list:
|
||||
return
|
||||
img_id = None
|
||||
if len(msg) > 1:
|
||||
img_id = msg[1]
|
||||
path = _path / cn2py(gallery)
|
||||
if gallery in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if gallery in image_dir_list:
|
||||
if not path.exists() and (path.parent.parent / cn2py(gallery)).exists():
|
||||
path = IMAGE_PATH / cn2py(gallery)
|
||||
else:
|
||||
@ -76,9 +77,10 @@ async def _(event: MessageEvent):
|
||||
result = image(path / f"{index}.jpg")
|
||||
if result:
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
||||
f"发送{cn2py(gallery)}:" + result
|
||||
f"发送{cn2py(gallery)}:" + str(path / f"{index}.jpg"),
|
||||
"发送图片",
|
||||
event.user_id,
|
||||
getattr(event, "group_id", None),
|
||||
)
|
||||
msg_id = await send_img.send(
|
||||
f"id:{index}" + result
|
||||
@ -92,9 +94,10 @@ async def _(event: MessageEvent):
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
||||
f"发送 {cn2py(gallery)} 失败"
|
||||
f"发送 {cn2py(gallery)} 失败",
|
||||
"发送图片",
|
||||
event.user_id,
|
||||
getattr(event, "group_id", None),
|
||||
)
|
||||
await send_img.finish(f"不想给你看Ov|")
|
||||
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from configs.config import Config
|
||||
from utils.utils import get_message_img
|
||||
from .data_source import upload_image_to_local
|
||||
from nonebot.params import CommandArg, Arg, ArgStr
|
||||
from typing import List
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent
|
||||
from nonebot.params import Arg, ArgStr, CommandArg
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
|
||||
from configs.config import Config
|
||||
from utils.depends import ImageList
|
||||
from utils.utils import get_message_img
|
||||
|
||||
from .data_source import upload_image_to_local
|
||||
|
||||
__zx_plugin_name__ = "上传图片 [Admin]"
|
||||
__plugin_usage__ = """
|
||||
@ -37,27 +40,37 @@ show_gallery = on_command("查看公开图库", priority=1, block=True)
|
||||
|
||||
@show_gallery.handle()
|
||||
async def _():
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await show_gallery.finish("未发现任何图库")
|
||||
x = "公开图库列表:\n"
|
||||
for i, e in enumerate(Config.get_config("image_management", "IMAGE_DIR_LIST")):
|
||||
for i, e in enumerate(image_dir_list):
|
||||
x += f"\t{i+1}.{e}\n"
|
||||
await show_gallery.send(x[:-1])
|
||||
|
||||
|
||||
@upload_img.handle()
|
||||
async def _(event: MessageEvent, state: T_State, arg: Message = CommandArg()):
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
arg: Message = CommandArg(),
|
||||
img_list: List[str] = ImageList(),
|
||||
):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST")
|
||||
if not image_dir_list:
|
||||
await show_gallery.finish("未发现任何图库")
|
||||
args = arg.extract_plain_text().strip()
|
||||
img_list = get_message_img(event.json())
|
||||
if args:
|
||||
if args in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if args in image_dir_list:
|
||||
state["path"] = args
|
||||
if img_list:
|
||||
state["img_list"] = arg
|
||||
state["dir_list"] = "\n-".join(image_dir_list)
|
||||
|
||||
|
||||
@upload_img.got(
|
||||
"path",
|
||||
prompt=f"请选择要上传的图库\n- "
|
||||
+ "\n- ".join(Config.get_config("image_management", "IMAGE_DIR_LIST")),
|
||||
prompt=Message.template("请选择要上传的图库\n-{dir_list}"),
|
||||
)
|
||||
@upload_img.got("img_list", prompt="图呢图呢图呢图呢!GKD!")
|
||||
async def _(
|
||||
@ -65,13 +78,13 @@ async def _(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
path: str = ArgStr("path"),
|
||||
img_list: Message = Arg("img_list"),
|
||||
img_list: List[str] = ImageList(),
|
||||
):
|
||||
if path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
if path not in image_dir_list:
|
||||
await upload_img.reject_arg("path", "此目录不正确,请重新输入目录!")
|
||||
if not get_message_img(img_list):
|
||||
if not img_list:
|
||||
await upload_img.reject_arg("img_list", "图呢图呢图呢图呢!GKD!")
|
||||
img_list = get_message_img(img_list)
|
||||
group_id = 0
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
@ -81,37 +94,41 @@ async def _(
|
||||
|
||||
|
||||
@continuous_upload_img.handle()
|
||||
async def _(event: MessageEvent, state: T_State):
|
||||
path = get_message_img(event.json())
|
||||
if path in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
arg: Message = CommandArg(),
|
||||
img_list: List[str] = ImageList(),
|
||||
):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
path = arg.extract_plain_text().strip()
|
||||
if path in image_dir_list:
|
||||
state["path"] = path
|
||||
state["img_list"] = []
|
||||
state["dir_list"] = "\n-".join(image_dir_list)
|
||||
|
||||
|
||||
@continuous_upload_img.got(
|
||||
"path",
|
||||
prompt=f"请选择要上传的图库\n- "
|
||||
+ "\n- ".join(Config.get_config("image_management", "IMAGE_DIR_LIST")),
|
||||
)
|
||||
@continuous_upload_img.got("path", prompt=Message.template("请选择要上传的图库\n-{dir_list}"))
|
||||
@continuous_upload_img.got("img", prompt="图呢图呢图呢图呢!GKD!【发送‘stop’为停止】")
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
img_list: List[str] = Arg("img_list"),
|
||||
collect_img_list: List[str] = Arg("img_list"),
|
||||
path: str = ArgStr("path"),
|
||||
img: Message = Arg("img"),
|
||||
img_list: List[str] = ImageList(),
|
||||
):
|
||||
if path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
image_dir_list = Config.get_config("image_management", "IMAGE_DIR_LIST") or []
|
||||
if path not in image_dir_list:
|
||||
await upload_img.reject_arg("path", "此目录不正确,请重新输入目录!")
|
||||
if not img.extract_plain_text() == "stop":
|
||||
img = get_message_img(img)
|
||||
if img:
|
||||
for i in img:
|
||||
img_list.append(i)
|
||||
if img_list:
|
||||
for i in img_list:
|
||||
collect_img_list.append(i)
|
||||
await upload_img.reject_arg("img", "图再来!!【发送‘stop’为停止】")
|
||||
group_id = 0
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
await continuous_upload_img.send(
|
||||
await upload_image_to_local(img_list, path, event.user_id, group_id)
|
||||
await upload_image_to_local(collect_img_list, path, event.user_id, group_id)
|
||||
)
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
from configs.config import NICKNAME
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
from configs.config import NICKNAME
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from services.log import logger
|
||||
from utils.utils import cn2py
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import os
|
||||
|
||||
from utils.utils import cn2py
|
||||
|
||||
_path = IMAGE_PATH / "image_management"
|
||||
|
||||
@ -31,8 +31,10 @@ async def upload_image_to_local(
|
||||
for img in failed_list:
|
||||
failed_result += str(img) + "\n"
|
||||
logger.info(
|
||||
f"USER {user_id} GROUP {group_id}"
|
||||
f" 上传图片至 {_path_name} 共 {len(img_list)} 张,失败 {len(failed_list)} 张,id={success_id[:-1]}"
|
||||
f"上传图片至 {_path_name} 共 {len(img_list)} 张,失败 {len(failed_list)} 张,id={success_id[:-1]}",
|
||||
"上传图片",
|
||||
user_id,
|
||||
group_id,
|
||||
)
|
||||
if failed_list:
|
||||
return (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user