mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
update 0.0.7.0
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from configs.config import Config
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from pathlib import Path
|
||||
import nonebot
|
||||
|
||||
|
||||
@@ -44,5 +46,16 @@ Config.add_plugin_config(
|
||||
default_value=6,
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management",
|
||||
"SHOW_ID",
|
||||
True,
|
||||
help_="是否消息显示图片下标id",
|
||||
default_value=True
|
||||
)
|
||||
|
||||
|
||||
(Path(IMAGE_PATH) / "image_management").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
nonebot.load_plugins("plugins/image_management")
|
||||
|
||||
@@ -31,12 +31,17 @@ __plugin_settings__ = {
|
||||
delete_img = on_command("删除图片", priority=5, rule=to_me(), block=True)
|
||||
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
|
||||
|
||||
@delete_img.args_parser
|
||||
async def parse(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if get_message_text(event.json()) in ["取消", "算了"]:
|
||||
await delete_img.finish("已取消操作..", at_sender=True)
|
||||
if state["_current_key"] in ["path"]:
|
||||
if get_message_text(event.json()) not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
if get_message_text(event.json()) not in Config.get_config(
|
||||
"image_management", "IMAGE_DIR_LIST"
|
||||
):
|
||||
await delete_img.reject("此目录不正确,请重新输入目录!")
|
||||
state[state["_current_key"]] = get_message_text(event.json())
|
||||
if state["_current_key"] == "id":
|
||||
@@ -52,7 +57,11 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
args = raw_arg.split(" ")
|
||||
if args[0] in ["帮助"]:
|
||||
await delete_img.finish(__plugin_usage__)
|
||||
if len(args) >= 2 and args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST") and is_number(args[1]):
|
||||
if (
|
||||
len(args) >= 2
|
||||
and args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST")
|
||||
and is_number(args[1])
|
||||
):
|
||||
state["path"] = args[0]
|
||||
state["id"] = args[1]
|
||||
|
||||
@@ -60,18 +69,18 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
@delete_img.got("path", prompt="请输入要删除的目标图库?")
|
||||
@delete_img.got("id", prompt="请输入要删除的图片id?")
|
||||
async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
|
||||
path = cn2py(state["path"])
|
||||
img_id = state["id"]
|
||||
# path = IMAGE_PATH + path
|
||||
path = Path(IMAGE_PATH) / path
|
||||
temp = Path(IMAGE_PATH) / "temp"
|
||||
path = _path / cn2py(state["path"])
|
||||
if not path.exists() and (path.parent.parent / cn2py(state["path"])).exists():
|
||||
path = path.parent.parent / cn2py(state["path"])
|
||||
temp = Path(TEMP_PATH)
|
||||
max_id = len(os.listdir(path)) - 1
|
||||
if int(img_id) > max_id or int(img_id) < 0:
|
||||
await delete_img.finish(f"Id超过上下限,上限:{max_id}", at_sender=True)
|
||||
try:
|
||||
if os.path.exists(temp / "delete.jpg"):
|
||||
os.remove(temp / "delete.jpg")
|
||||
logger.info("删除图片 delete.jpg 成功")
|
||||
if (temp / "delete.jpg").exists():
|
||||
(temp / "delete.jpg").unlink()
|
||||
logger.info(f"删除{cn2py(state['path'])}图片 {img_id}.jpg 成功")
|
||||
except Exception as e:
|
||||
logger.warning(f"删除图片 delete.jpg 失败 e{e}")
|
||||
try:
|
||||
|
||||
@@ -31,6 +31,9 @@ __plugin_settings__ = {
|
||||
move_img = on_command("移动图片", priority=5, rule=to_me(), block=True)
|
||||
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
|
||||
|
||||
@move_img.args_parser
|
||||
async def parse(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if str(event.get_message()) in ["取消", "算了"]:
|
||||
@@ -72,8 +75,20 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
@move_img.got("id", prompt="要移动的图片id是?")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
img_id = state["id"]
|
||||
source_path = Path(IMAGE_PATH) / cn2py(state["source_path"])
|
||||
destination_path = Path(IMAGE_PATH) / cn2py(state["destination_path"])
|
||||
source_path = _path / cn2py(state["source_path"])
|
||||
destination_path = _path / cn2py(state["destination_path"])
|
||||
if (
|
||||
not source_path.exists()
|
||||
and (source_path.parent.parent / cn2py(state["source_path"])).exists()
|
||||
):
|
||||
source_path = source_path.parent.parent / cn2py(state["source_path"])
|
||||
if (
|
||||
not destination_path.exists()
|
||||
and (destination_path.parent.parent / cn2py(state["destination_path"])).exists()
|
||||
):
|
||||
destination_path = destination_path.parent.parent / cn2py(
|
||||
state["destination_path"]
|
||||
)
|
||||
destination_path.mkdir(parents=True, exist_ok=True)
|
||||
max_id = len(os.listdir(source_path)) - 1
|
||||
des_max_id = len(os.listdir(destination_path))
|
||||
|
||||
@@ -6,6 +6,7 @@ from services.log import logger
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from utils.utils import FreqLimiter, cn2py
|
||||
from pathlib import Path
|
||||
from configs.config import Config
|
||||
from utils.manager import group_manager, withdraw_message_manager
|
||||
import random
|
||||
@@ -16,7 +17,7 @@ try:
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
__zx_plugin_name__ = "发送本地图库图片"
|
||||
__zx_plugin_name__ = "本地图库"
|
||||
__plugin_usage__ = f"""
|
||||
usage:
|
||||
发送指定图库下的随机或指定id图片
|
||||
@@ -37,49 +38,61 @@ __plugin_settings__ = {
|
||||
"cmd": ["发送图片"] + Config.get_config("image_management", "IMAGE_DIR_LIST"),
|
||||
}
|
||||
__plugin_task__ = {"pa": "丢人爬"}
|
||||
__plugin_resources__ = {
|
||||
"pa": IMAGE_PATH
|
||||
}
|
||||
__plugin_resources__ = {"pa": IMAGE_PATH}
|
||||
|
||||
Config.add_plugin_config(
|
||||
"_task",
|
||||
"DEFAULT_PA",
|
||||
True,
|
||||
help_="被动 爬 进群默认开关状态",
|
||||
default_value=True,
|
||||
)
|
||||
|
||||
_flmt = FreqLimiter(1)
|
||||
|
||||
cmd = set(Config.get_config("image_management", "IMAGE_DIR_LIST"))
|
||||
|
||||
# print(cmd)
|
||||
|
||||
send_img = on_command("img", aliases=cmd, priority=5, block=True)
|
||||
pa = on_keyword({"丢人爬", "爪巴"}, priority=5, block=True)
|
||||
pa_reg = on_regex("^爬$", priority=5, block=True)
|
||||
|
||||
search_url = "https://api.fantasyzone.cc/tu/search.php"
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
|
||||
|
||||
@send_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
img_id = get_message_text(event.json())
|
||||
path = cn2py(state["_prefix"]["raw_command"]) + "/"
|
||||
path = _path / cn2py(state["_prefix"]["raw_command"])
|
||||
if state["_prefix"]["raw_command"] in Config.get_config(
|
||||
"image_management", "IMAGE_DIR_LIST"
|
||||
):
|
||||
if not os.path.exists(f"{IMAGE_PATH}/{path}/"):
|
||||
os.mkdir(f"{IMAGE_PATH}/{path}/")
|
||||
length = len(os.listdir(IMAGE_PATH + path))
|
||||
if not path.exists() and (path.parent.parent / cn2py(state["_prefix"]["raw_command"])).exists():
|
||||
path = Path(IMAGE_PATH) / cn2py(state["_prefix"]["raw_command"])
|
||||
else:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
length = len(os.listdir(path))
|
||||
if length == 0:
|
||||
logger.warning(f"图库 {path} 为空,调用取消!")
|
||||
logger.warning(f'图库 {cn2py(state["_prefix"]["raw_command"])} 为空,调用取消!')
|
||||
await send_img.finish("该图库中没有图片噢")
|
||||
index = img_id if img_id else str(random.randint(0, length - 1))
|
||||
if not is_number(index):
|
||||
return
|
||||
if int(index) > length - 1 or int(index) < 0:
|
||||
await send_img.finish(f"超过当前上下限!({length - 1})")
|
||||
result = image(f"{index}.jpg", path)
|
||||
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'}) 发送{path}:"
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
||||
f"发送{cn2py(state['_prefix']['raw_command'])}:"
|
||||
+ result
|
||||
)
|
||||
msg_id = await send_img.send(f"id:{index}" + result)
|
||||
msg_id = await send_img.send(
|
||||
f"id:{index}" + result
|
||||
if Config.get_config("image_management", "SHOW_ID")
|
||||
else "" + result
|
||||
)
|
||||
withdraw_message_manager.withdraw_message(
|
||||
event,
|
||||
msg_id,
|
||||
@@ -88,7 +101,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
else:
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送 {path} 失败"
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
||||
f"发送 {cn2py(state['_prefix']['raw_command'])} 失败"
|
||||
)
|
||||
await send_img.finish(f"不想给你看Ov|")
|
||||
|
||||
|
||||
@@ -8,11 +8,16 @@ from utils.http_utils import AsyncHttpx
|
||||
import os
|
||||
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
|
||||
|
||||
async def upload_image_to_local(
|
||||
img_list: List[str], path: str, user_id: int, group_id: int = 0
|
||||
img_list: List[str], path_: str, user_id: int, group_id: int = 0
|
||||
) -> str:
|
||||
_path = path
|
||||
path = Path(IMAGE_PATH) / cn2py(path)
|
||||
_path_name = path_
|
||||
path = _path / cn2py(path_)
|
||||
if not path.exists() and (path.parent.parent / cn2py(path_)).exists():
|
||||
path = path.parent.parent / cn2py(path_)
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
img_id = len(os.listdir(path))
|
||||
failed_list = []
|
||||
@@ -28,15 +33,15 @@ async def upload_image_to_local(
|
||||
failed_result += str(img) + "\n"
|
||||
logger.info(
|
||||
f"USER {user_id} GROUP {group_id}"
|
||||
f" 上传图片至 {_path} 共 {len(img_list)} 张,失败 {len(failed_list)} 张,id={success_id[:-1]}"
|
||||
f" 上传图片至 {_path_name} 共 {len(img_list)} 张,失败 {len(failed_list)} 张,id={success_id[:-1]}"
|
||||
)
|
||||
if failed_list:
|
||||
return (
|
||||
f"这次一共为 {_path}库 添加了 {len(img_list) - len(failed_list)} 张图片\n"
|
||||
f"这次一共为 {_path_name}库 添加了 {len(img_list) - len(failed_list)} 张图片\n"
|
||||
f"依次的Id为:{success_id[:-1]}\n上传失败:{failed_result[:-1]}\n{NICKNAME}感谢您对图库的扩充!WW"
|
||||
)
|
||||
else:
|
||||
return (
|
||||
f"这次一共为 {_path}库 添加了 {len(img_list)} 张图片\n依次的Id为:"
|
||||
f"这次一共为 {_path_name}库 添加了 {len(img_list)} 张图片\n依次的Id为:"
|
||||
f"{success_id[:-1]}\n{NICKNAME}感谢您对图库的扩充!WW"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user