2023-02-18 18:46:54 +08:00
|
|
|
|
import os
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
2022-02-19 18:20:19 +08:00
|
|
|
|
from nonebot import on_message, on_regex
|
2023-02-18 18:46:54 +08:00
|
|
|
|
from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent
|
|
|
|
|
|
|
|
|
|
|
|
from configs.config import Config
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from configs.path_config import IMAGE_PATH
|
|
|
|
|
|
from services.log import logger
|
2022-02-19 18:20:19 +08:00
|
|
|
|
from utils.manager import withdraw_message_manager
|
2023-02-18 18:46:54 +08:00
|
|
|
|
from utils.message_builder import image
|
|
|
|
|
|
from utils.utils import FreqLimiter, cn2py, get_message_text, is_number
|
|
|
|
|
|
|
2022-02-09 20:05:49 +08:00
|
|
|
|
from .rule import rule
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
2021-12-16 11:16:28 +08:00
|
|
|
|
__zx_plugin_name__ = "本地图库"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
__plugin_usage__ = f"""
|
|
|
|
|
|
usage:
|
2022-01-05 22:32:59 +08:00
|
|
|
|
发送指定图库下的随机或指定id图片genshin_memo
|
2021-11-23 21:44:59 +08:00
|
|
|
|
指令:
|
|
|
|
|
|
{Config.get_config("image_management", "IMAGE_DIR_LIST")} ?[id]
|
|
|
|
|
|
示例:美图
|
|
|
|
|
|
示例: 萝莉 2
|
|
|
|
|
|
""".strip()
|
|
|
|
|
|
__plugin_des__ = "让看看我的私藏,指[图片]"
|
|
|
|
|
|
__plugin_cmd__ = Config.get_config("image_management", "IMAGE_DIR_LIST")
|
|
|
|
|
|
__plugin_type__ = ("来点好康的",)
|
|
|
|
|
|
__plugin_version__ = 0.1
|
|
|
|
|
|
__plugin_author__ = "HibiKier"
|
|
|
|
|
|
__plugin_settings__ = {
|
|
|
|
|
|
"level": 5,
|
|
|
|
|
|
"default_status": True,
|
|
|
|
|
|
"limit_superuser": False,
|
2023-02-26 22:17:26 +08:00
|
|
|
|
"cmd": ["发送图片"] + (Config.get_config("image_management", "IMAGE_DIR_LIST") or []),
|
2021-11-23 21:44:59 +08:00
|
|
|
|
}
|
2022-05-29 20:47:18 +08:00
|
|
|
|
__plugin_resources__ = {"pa": IMAGE_PATH / "pa"}
|
2021-12-16 11:16:28 +08:00
|
|
|
|
|
|
|
|
|
|
Config.add_plugin_config(
|
2023-02-26 22:17:26 +08:00
|
|
|
|
"_task", "DEFAULT_PA", True, help_="被动 爬 进群默认开关状态", default_value=True, type=int
|
2021-12-16 11:16:28 +08:00
|
|
|
|
)
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
_flmt = FreqLimiter(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 20:05:49 +08:00
|
|
|
|
send_img = on_message(priority=5, rule=rule, block=True)
|
2022-02-19 18:20:19 +08:00
|
|
|
|
pa_reg = on_regex("^(爬|丢人爬|爪巴)$", priority=5, block=True)
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
2021-12-16 11:16:28 +08:00
|
|
|
|
|
2022-02-19 18:20:19 +08:00
|
|
|
|
_path = IMAGE_PATH / "image_management"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@send_img.handle()
|
2022-02-20 11:06:04 +08:00
|
|
|
|
async def _(event: MessageEvent):
|
|
|
|
|
|
msg = get_message_text(event.json()).split()
|
2022-02-09 20:05:49 +08:00
|
|
|
|
gallery = msg[0]
|
|
|
|
|
|
if gallery not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
|
|
|
|
|
return
|
|
|
|
|
|
img_id = None
|
|
|
|
|
|
if len(msg) > 1:
|
|
|
|
|
|
img_id = msg[1]
|
|
|
|
|
|
path = _path / cn2py(gallery)
|
2023-02-18 18:46:54 +08:00
|
|
|
|
if gallery in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
2022-02-09 20:05:49 +08:00
|
|
|
|
if not path.exists() and (path.parent.parent / cn2py(gallery)).exists():
|
2022-02-19 18:20:19 +08:00
|
|
|
|
path = IMAGE_PATH / cn2py(gallery)
|
2021-12-16 11:16:28 +08:00
|
|
|
|
else:
|
|
|
|
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
length = len(os.listdir(path))
|
2021-11-23 21:44:59 +08:00
|
|
|
|
if length == 0:
|
2023-02-18 18:46:54 +08:00
|
|
|
|
logger.warning(f"图库 {cn2py(gallery)} 为空,调用取消!")
|
2021-11-23 21:44:59 +08:00
|
|
|
|
await send_img.finish("该图库中没有图片噢")
|
2021-11-24 09:56:50 +08:00
|
|
|
|
index = img_id if img_id else str(random.randint(0, length - 1))
|
2021-11-23 21:44:59 +08:00
|
|
|
|
if not is_number(index):
|
|
|
|
|
|
return
|
|
|
|
|
|
if int(index) > length - 1 or int(index) < 0:
|
|
|
|
|
|
await send_img.finish(f"超过当前上下限!({length - 1})")
|
2021-12-16 11:16:28 +08:00
|
|
|
|
result = image(path / f"{index}.jpg")
|
2021-11-23 21:44:59 +08:00
|
|
|
|
if result:
|
|
|
|
|
|
logger.info(
|
|
|
|
|
|
f"(USER {event.user_id}, GROUP "
|
2021-12-16 11:16:28 +08:00
|
|
|
|
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
2023-02-18 18:46:54 +08:00
|
|
|
|
f"发送{cn2py(gallery)}:" + result
|
2021-11-23 21:44:59 +08:00
|
|
|
|
)
|
2021-12-16 11:16:28 +08:00
|
|
|
|
msg_id = await send_img.send(
|
|
|
|
|
|
f"id:{index}" + result
|
|
|
|
|
|
if Config.get_config("image_management", "SHOW_ID")
|
|
|
|
|
|
else "" + result
|
|
|
|
|
|
)
|
2021-11-23 21:44:59 +08:00
|
|
|
|
withdraw_message_manager.withdraw_message(
|
|
|
|
|
|
event,
|
|
|
|
|
|
msg_id,
|
|
|
|
|
|
Config.get_config("image_management", "WITHDRAW_IMAGE_MESSAGE"),
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
logger.info(
|
|
|
|
|
|
f"(USER {event.user_id}, GROUP "
|
2021-12-16 11:16:28 +08:00
|
|
|
|
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) "
|
2022-02-09 20:05:49 +08:00
|
|
|
|
f"发送 {cn2py(gallery)} 失败"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
)
|
|
|
|
|
|
await send_img.finish(f"不想给你看Ov|")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pa_reg.handle()
|
2022-02-19 18:20:19 +08:00
|
|
|
|
async def _(event: MessageEvent):
|
2021-11-23 21:44:59 +08:00
|
|
|
|
if _flmt.check(event.user_id):
|
|
|
|
|
|
_flmt.start_cd(event.user_id)
|
2023-02-18 18:46:54 +08:00
|
|
|
|
await pa_reg.finish(
|
|
|
|
|
|
image(IMAGE_PATH / "pa" / random.choice(os.listdir(IMAGE_PATH / "pa")))
|
|
|
|
|
|
)
|