mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
fit nonebot.beta2
This commit is contained in:
@@ -55,7 +55,7 @@ Config.add_plugin_config(
|
||||
)
|
||||
|
||||
|
||||
(Path(IMAGE_PATH) / "image_management").mkdir(parents=True, exist_ok=True)
|
||||
(IMAGE_PATH / "image_management").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
nonebot.load_plugins("plugins/image_management")
|
||||
|
||||
@@ -4,10 +4,10 @@ from services.log import logger
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from utils.utils import is_number, cn2py, get_message_text
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent, GroupMessageEvent, Message
|
||||
from utils.utils import is_number, cn2py
|
||||
from configs.config import Config
|
||||
from pathlib import Path
|
||||
from nonebot.params import CommandArg, Arg
|
||||
import os
|
||||
|
||||
__zx_plugin_name__ = "删除图片 [Admin]"
|
||||
@@ -31,60 +31,47 @@ __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"
|
||||
):
|
||||
await delete_img.reject("此目录不正确,请重新输入目录!")
|
||||
state[state["_current_key"]] = get_message_text(event.json())
|
||||
if state["_current_key"] == "id":
|
||||
if not is_number(get_message_text(event.json())):
|
||||
await delete_img.reject("id不正确!请重新输入数字...")
|
||||
state[state["_current_key"]] = get_message_text(event.json())
|
||||
_path = IMAGE_PATH / "image_management"
|
||||
|
||||
|
||||
@delete_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
raw_arg = get_message_text(event.json()).strip()
|
||||
if raw_arg:
|
||||
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])
|
||||
):
|
||||
async def _(state: T_State, arg: Message = CommandArg()):
|
||||
args = arg.extract_plain_text().strip().split()
|
||||
if args:
|
||||
if args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = args[0]
|
||||
if len(args) > 1 and is_number(args[1]):
|
||||
state["id"] = args[1]
|
||||
|
||||
|
||||
@delete_img.got("path", prompt="请输入要删除的目标图库?")
|
||||
@delete_img.got("id", prompt="请输入要删除的图片id?")
|
||||
async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
|
||||
img_id = state["id"]
|
||||
path = _path / cn2py(state["path"])
|
||||
async def arg_handle(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
path: str = Arg("path"),
|
||||
img_id: str = Arg("id"),
|
||||
):
|
||||
if path in ["取消", "算了"] or img_id in ["取消", "算了"]:
|
||||
await delete_img.finish("已取消操作...")
|
||||
if path not in Config.get_config("image_management", "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)
|
||||
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 (temp / "delete.jpg").exists():
|
||||
(temp / "delete.jpg").unlink()
|
||||
if (TEMP_PATH / "delete.jpg").exists():
|
||||
(TEMP_PATH / "delete.jpg").unlink()
|
||||
logger.info(f"删除{cn2py(state['path'])}图片 {img_id}.jpg 成功")
|
||||
except Exception as e:
|
||||
logger.warning(f"删除图片 delete.jpg 失败 e{e}")
|
||||
try:
|
||||
os.rename(path / f"{img_id}.jpg", temp / "delete.jpg")
|
||||
os.rename(path / f"{img_id}.jpg", TEMP_PATH / f"{event.user_id}_delete.jpg")
|
||||
logger.info(f"移动 {path}/{img_id}.jpg 移动成功")
|
||||
except Exception as e:
|
||||
logger.warning(f"{path}/{img_id}.jpg --> 移动失败 e:{e}")
|
||||
@@ -100,6 +87,6 @@ async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
|
||||
f" -> id: {img_id} 删除成功"
|
||||
)
|
||||
await delete_img.finish(
|
||||
f"id: {img_id} 删除成功" + image("delete.jpg", TEMP_PATH), 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} 删除失败!")
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import os
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent, GroupMessageEvent, Message
|
||||
from configs.config import Config
|
||||
from utils.utils import is_number, cn2py
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot.params import CommandArg, ArgStr
|
||||
import os
|
||||
|
||||
__zx_plugin_name__ = "移动图片 [Admin]"
|
||||
__plugin_usage__ = """
|
||||
@@ -31,71 +30,63 @@ __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 ["取消", "算了"]:
|
||||
await move_img.finish("已取消操作..", at_sender=True)
|
||||
if state["_current_key"] in ["source_path", "destination_path"]:
|
||||
if str(event.get_message()) not in Config.get_config(
|
||||
"image_management", "IMAGE_DIR_LIST"
|
||||
):
|
||||
await move_img.reject("此目录不正确,请重新输入目录!")
|
||||
state[state["_current_key"]] = str(event.get_message())
|
||||
if state["_current_key"] == "id":
|
||||
if not is_number(str(event.get_message())):
|
||||
await move_img.reject("id不正确!请重新输入数字...")
|
||||
state[state["_current_key"]] = str(event.get_message())
|
||||
_path = IMAGE_PATH / "image_management"
|
||||
|
||||
|
||||
@move_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
raw_arg = str(event.get_message()).strip()
|
||||
if raw_arg:
|
||||
args = raw_arg.split(" ")
|
||||
if args[0] in ["帮助"]:
|
||||
await move_img.finish(__plugin_usage__)
|
||||
if (
|
||||
len(args) >= 3
|
||||
and args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST")
|
||||
and args[1] in Config.get_config("image_management", "IMAGE_DIR_LIST")
|
||||
and is_number(args[2])
|
||||
):
|
||||
state["source_path"] = args[0]
|
||||
state["destination_path"] = args[1]
|
||||
async def _(state: T_State, arg: Message = CommandArg()):
|
||||
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"):
|
||||
state["source_path"] = args[0]
|
||||
if n > 1:
|
||||
if args[1] in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["destination_path"] = args[1]
|
||||
if n > 2 and is_number(args[2]):
|
||||
state["id"] = args[2]
|
||||
else:
|
||||
await move_img.finish("参数错误,请重试", at_sender=True)
|
||||
|
||||
|
||||
@move_img.got("source_path", prompt="要从哪个图库移出?")
|
||||
@move_img.got("destination_path", prompt="要移动到哪个图库?")
|
||||
@move_img.got("id", prompt="要移动的图片id是?")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
img_id = state["id"]
|
||||
source_path = _path / cn2py(state["source_path"])
|
||||
destination_path = _path / cn2py(state["destination_path"])
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
source_path: str = ArgStr("source_path"),
|
||||
destination_path: str = ArgStr("destination_path"),
|
||||
img_id: str = ArgStr("id"),
|
||||
):
|
||||
if (
|
||||
not source_path.exists()
|
||||
and (source_path.parent.parent / cn2py(state["source_path"])).exists()
|
||||
source_path in ["取消", "算了"]
|
||||
or img_id in ["取消", "算了"]
|
||||
or destination_path in ["取消", "算了"]
|
||||
):
|
||||
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)
|
||||
await move_img.finish("已取消操作...")
|
||||
if source_path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
await move_img.reject_arg("source_path", "移除目录不正确,请重新输入!")
|
||||
if destination_path not in Config.get_config("image_management", "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)
|
||||
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)
|
||||
if not destination_path.exists():
|
||||
if (destination_path.parent.parent / cn2py(destination_path.name)).exists():
|
||||
source_path = destination_path.parent.parent / cn2py(destination_path.name)
|
||||
source_path.mkdir(exist_ok=True, parents=True)
|
||||
destination_path.mkdir(exist_ok=True, parents=True)
|
||||
if not len(os.listdir(source_path)):
|
||||
await move_img.finish(f"{source_path}图库中没有任何图片,移动失败。")
|
||||
max_id = len(os.listdir(source_path)) - 1
|
||||
des_max_id = len(os.listdir(destination_path))
|
||||
if int(img_id) > max_id or int(img_id) < 0:
|
||||
await move_img.finish(f"Id超过上下限,上限:{max_id}", at_sender=True)
|
||||
try:
|
||||
os.rename(source_path / f"{img_id}.jpg", destination_path / f"{des_max_id}.jpg")
|
||||
move_file = source_path / f"{img_id}.jpg"
|
||||
move_file.rename(destination_path / f"{des_max_id}.jpg")
|
||||
logger.info(
|
||||
f"移动 {source_path}/{img_id}.jpg ---> {destination_path}/{des_max_id} 移动成功"
|
||||
)
|
||||
@@ -106,7 +97,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
await move_img.finish(f"移动图片id:{img_id} 失败了...", at_sender=True)
|
||||
if max_id > 0:
|
||||
try:
|
||||
os.rename(source_path / f"{max_id}.jpg", source_path / f"{img_id}.jpg")
|
||||
rep_file = source_path / f"{max_id}.jpg"
|
||||
rep_file.rename(source_path / f"{img_id}.jpg")
|
||||
logger.info(f"{source_path}/{max_id}.jpg 替换 {source_path}/{img_id}.jpg 成功")
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from nonebot import on_message, on_keyword, on_regex
|
||||
from nonebot import on_message, on_regex
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from utils.message_builder import image
|
||||
from utils.utils import get_message_text, is_number
|
||||
from utils.utils import is_number
|
||||
from services.log import logger
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent, GroupMessageEvent, Message
|
||||
from utils.utils import FreqLimiter, cn2py
|
||||
from pathlib import Path
|
||||
from configs.config import Config
|
||||
from utils.manager import group_manager, withdraw_message_manager
|
||||
from utils.manager import withdraw_message_manager
|
||||
from nonebot.params import CommandArg
|
||||
from .rule import rule
|
||||
import random
|
||||
import os
|
||||
@@ -38,7 +37,6 @@ __plugin_settings__ = {
|
||||
"limit_superuser": False,
|
||||
"cmd": ["发送图片"] + Config.get_config("image_management", "IMAGE_DIR_LIST"),
|
||||
}
|
||||
__plugin_task__ = {"pa": "丢人爬"}
|
||||
__plugin_resources__ = {"pa": IMAGE_PATH}
|
||||
|
||||
Config.add_plugin_config(
|
||||
@@ -53,16 +51,15 @@ _flmt = FreqLimiter(1)
|
||||
|
||||
|
||||
send_img = on_message(priority=5, rule=rule, block=True)
|
||||
pa = on_keyword({"丢人爬", "爪巴"}, priority=5, block=True)
|
||||
pa_reg = on_regex("^爬$", priority=5, block=True)
|
||||
pa_reg = on_regex("^(爬|丢人爬|爪巴)$", priority=5, block=True)
|
||||
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
_path = IMAGE_PATH / "image_management"
|
||||
|
||||
|
||||
@send_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json()).split()
|
||||
async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip().split()
|
||||
gallery = msg[0]
|
||||
if gallery not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
return
|
||||
@@ -74,7 +71,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
"image_management", "IMAGE_DIR_LIST"
|
||||
):
|
||||
if not path.exists() and (path.parent.parent / cn2py(gallery)).exists():
|
||||
path = Path(IMAGE_PATH) / cn2py(gallery)
|
||||
path = IMAGE_PATH / cn2py(gallery)
|
||||
else:
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
length = len(os.listdir(path))
|
||||
@@ -113,32 +110,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
await send_img.finish(f"不想给你看Ov|")
|
||||
|
||||
|
||||
@pa.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if (
|
||||
isinstance(event, GroupMessageEvent)
|
||||
and not await group_manager.check_group_task_status(event.group_id, "pa")
|
||||
or get_message_text(event.json()).startswith("开启")
|
||||
or get_message_text(event.json()).startswith("关闭")
|
||||
):
|
||||
return
|
||||
msg = get_message_text(event.json())
|
||||
if not msg or str(event.get_message()[:2]) in ["开启", "关闭"]:
|
||||
return
|
||||
if _flmt.check(event.user_id):
|
||||
_flmt.start_cd(event.user_id)
|
||||
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
|
||||
|
||||
|
||||
@pa_reg.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if (
|
||||
isinstance(event, GroupMessageEvent)
|
||||
and not await group_manager.check_group_task_status(event.group_id, "pa")
|
||||
or get_message_text(event.json()).startswith("开启")
|
||||
or get_message_text(event.json()).startswith("关闭")
|
||||
):
|
||||
return
|
||||
async def _(event: MessageEvent):
|
||||
if _flmt.check(event.user_id):
|
||||
_flmt.start_cd(event.user_id)
|
||||
await pa_reg.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
|
||||
await pa_reg.finish(image(random.choice(os.listdir(IMAGE_PATH / "pa")), "pa"))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from nonebot.adapters.cqhttp import Bot, Event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Event
|
||||
from nonebot.typing import T_State
|
||||
from utils.utils import get_message_text
|
||||
from configs.config import Config
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from configs.config import Config
|
||||
from utils.utils import get_message_img, get_message_text
|
||||
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
|
||||
|
||||
|
||||
__zx_plugin_name__ = "上传图片 [Admin]"
|
||||
@@ -22,7 +24,9 @@ __plugin_des__ = "指定图库图片上传"
|
||||
__plugin_cmd__ = ["上传图片 [图库] [图片]", "连续上传图片 [图库]", "查看公开图库"]
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {"admin_level": Config.get_config("image_management", "UPLOAD_IMAGE_LEVEL")}
|
||||
__plugin_settings__ = {
|
||||
"admin_level": Config.get_config("image_management", "UPLOAD_IMAGE_LEVEL")
|
||||
}
|
||||
|
||||
upload_img = on_command("上传图片", rule=to_me(), priority=5, block=True)
|
||||
|
||||
@@ -32,48 +36,42 @@ show_gallery = on_command("查看公开图库", priority=1, block=True)
|
||||
|
||||
|
||||
@show_gallery.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
x = '公开图库列表:\n'
|
||||
async def _():
|
||||
x = "公开图库列表:\n"
|
||||
for i, e in enumerate(Config.get_config("image_management", "IMAGE_DIR_LIST")):
|
||||
x += f'\t{i+1}.{e}\n'
|
||||
x += f"\t{i+1}.{e}\n"
|
||||
await show_gallery.send(x[:-1])
|
||||
|
||||
|
||||
@upload_img.args_parser
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if msg in ["取消", "算了"]:
|
||||
await upload_img.finish("已取消操作..", at_sender=True)
|
||||
if state["_current_key"] in ["path"]:
|
||||
if msg not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
await upload_img.reject("此目录不正确,请重新输入目录!")
|
||||
state["path"] = msg
|
||||
if state["_current_key"] in ["imgs"]:
|
||||
if not get_message_img(event.json()):
|
||||
await upload_img.reject("图呢图呢图呢图呢!GKD!")
|
||||
state["imgs"] = get_message_img(event.json())
|
||||
|
||||
|
||||
@upload_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
raw_arg = get_message_text(event.json())
|
||||
async def _(event: MessageEvent, state: T_State, arg: Message = CommandArg()):
|
||||
args = arg.extract_plain_text().strip()
|
||||
img_list = get_message_img(event.json())
|
||||
if raw_arg:
|
||||
if raw_arg in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = raw_arg
|
||||
if img_list:
|
||||
state["imgs"] = img_list
|
||||
if args:
|
||||
if args in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = args
|
||||
if img_list:
|
||||
state["img_list"] = arg
|
||||
|
||||
|
||||
@upload_img.got("path", prompt="要将图片上传至什么图库呢?")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
pass
|
||||
|
||||
|
||||
@upload_img.got("imgs", prompt="图呢图呢图呢图呢!GKD!")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
path = state["path"]
|
||||
img_list = state["imgs"]
|
||||
@upload_img.got(
|
||||
"path",
|
||||
prompt=f"请选择要上传的图库\n- "
|
||||
+ "\n- ".join(Config.get_config("image_management", "IMAGE_DIR_LIST")),
|
||||
)
|
||||
@upload_img.got("img_list", prompt="图呢图呢图呢图呢!GKD!")
|
||||
async def _(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
path: str = ArgStr("path"),
|
||||
img_list: Message = Arg("img_list"),
|
||||
):
|
||||
if path not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
await upload_img.reject_arg("path", "此目录不正确,请重新输入目录!")
|
||||
if not get_message_img(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
|
||||
@@ -82,42 +80,35 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
)
|
||||
|
||||
|
||||
@continuous_upload_img.args_parser
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if str(event.get_message()) in ["取消", "算了"]:
|
||||
await continuous_upload_img.finish("已取消操作..", at_sender=True)
|
||||
if state["_current_key"] in ["path"]:
|
||||
if str(event.get_message()) not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
await continuous_upload_img.reject("此目录不正确,请重新输入目录!")
|
||||
state[state["_current_key"]] = str(event.get_message())
|
||||
else:
|
||||
if get_message_text(event.json()) not in ["stop"]:
|
||||
img = get_message_img(event.json())
|
||||
if img:
|
||||
state["tmp"].extend(img)
|
||||
await continuous_upload_img.reject("图再来!!")
|
||||
else:
|
||||
state["imgs"] = state["tmp"]
|
||||
|
||||
|
||||
@continuous_upload_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(event: MessageEvent, state: T_State):
|
||||
path = get_message_img(event.json())
|
||||
if path in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = path
|
||||
await continuous_upload_img.send("图来!!【停止请发送 ‘stop’ 开始上传】")
|
||||
state["tmp"] = []
|
||||
state["img_list"] = []
|
||||
|
||||
|
||||
@continuous_upload_img.got("path", prompt="要将图片上传至什么图库呢?")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
pass
|
||||
|
||||
|
||||
@continuous_upload_img.got("imgs", prompt="图呢图呢图呢图呢!GKD!")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
path = state["path"]
|
||||
img_list = state["imgs"]
|
||||
@continuous_upload_img.got(
|
||||
"path",
|
||||
prompt=f"请选择要上传的图库\n- "
|
||||
+ "\n- ".join(Config.get_config("image_management", "IMAGE_DIR_LIST")),
|
||||
)
|
||||
@continuous_upload_img.got("img", prompt="图呢图呢图呢图呢!GKD!【发送‘stop’为停止】")
|
||||
async def _(
|
||||
event: MessageEvent,
|
||||
state: T_State,
|
||||
img_list: List[str] = Arg("img_list"),
|
||||
path: str = ArgStr("path"),
|
||||
img: Message = Arg("img"),
|
||||
):
|
||||
if path not in Config.get_config("image_management", "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)
|
||||
await upload_img.reject_arg("img", "图再来!!【发送‘stop’为停止】")
|
||||
group_id = 0
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
|
||||
@@ -3,12 +3,11 @@ from typing import List
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from services.log import logger
|
||||
from utils.utils import cn2py
|
||||
from pathlib import Path
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import os
|
||||
|
||||
|
||||
_path = Path(IMAGE_PATH) / "image_management"
|
||||
_path = IMAGE_PATH / "image_management"
|
||||
|
||||
|
||||
async def upload_image_to_local(
|
||||
|
||||
Reference in New Issue
Block a user