mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
update 0.0.6.0
This commit is contained in:
@@ -1,3 +1,48 @@
|
||||
from configs.config import Config
|
||||
import nonebot
|
||||
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management",
|
||||
"IMAGE_DIR_LIST",
|
||||
["美图", "萝莉", "壁纸"],
|
||||
name="图库操作",
|
||||
help_="公开图库列表,可自定义添加 [如果含有send_setu插件,请不要添加色图库]",
|
||||
default_value=[],
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management",
|
||||
"WITHDRAW_IMAGE_MESSAGE",
|
||||
(0, 1),
|
||||
name="图库操作",
|
||||
help_="自动撤回,参1:延迟撤回发送图库图片的时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
|
||||
default_value=(0, 1),
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management:delete_img",
|
||||
"DELETE_IMAGE_LEVEL [LEVEL]",
|
||||
7,
|
||||
help_="删除图库图片需要的管理员等级",
|
||||
default_value=7,
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management:move_img",
|
||||
"MOVE_IMAGE_LEVEL [LEVEL]",
|
||||
7,
|
||||
help_="移动图库图片需要的管理员等级",
|
||||
default_value=7,
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"image_management:upload_img",
|
||||
"UPLOAD_IMAGE_LEVEL [LEVEL]",
|
||||
6,
|
||||
help_="上传图库图片需要的管理员等级",
|
||||
default_value=6,
|
||||
)
|
||||
|
||||
|
||||
nonebot.load_plugins("plugins/image_management")
|
||||
|
||||
@@ -5,9 +5,8 @@ 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 configs.config import DELETE_IMG_LEVEL
|
||||
from configs.config import IMAGE_DIR_LIST
|
||||
from utils.utils import is_number, cn2py, get_message_text
|
||||
from configs.config import Config
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
@@ -25,7 +24,7 @@ __plugin_cmd__ = ["删除图片 [图库] [id]", "查看公开图库"]
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"admin_level": DELETE_IMG_LEVEL
|
||||
"admin_level": Config.get_config("image_management", "DELETE_IMAGE_LEVEL")
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +36,7 @@ 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 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":
|
||||
@@ -53,7 +52,7 @@ 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 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]
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ 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 configs.config import IMAGE_DIR_LIST, MOVE_IMG_LEVEL
|
||||
from configs.config import Config
|
||||
from utils.utils import is_number, cn2py
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from pathlib import Path
|
||||
@@ -24,7 +24,7 @@ __plugin_cmd__ = ["移动图片 [源图库] [目标图库] [id]", "查看公开
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"admin_level": MOVE_IMG_LEVEL
|
||||
"admin_level": Config.get_config("image_management", "MOVE_IMAGE_LEVEL")
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ 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 IMAGE_DIR_LIST:
|
||||
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":
|
||||
@@ -54,8 +56,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
await move_img.finish(__plugin_usage__)
|
||||
if (
|
||||
len(args) >= 3
|
||||
and args[0] in IMAGE_DIR_LIST
|
||||
and args[1] in IMAGE_DIR_LIST
|
||||
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]
|
||||
@@ -78,9 +80,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
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"
|
||||
)
|
||||
os.rename(source_path / f"{img_id}.jpg", destination_path / f"{des_max_id}.jpg")
|
||||
logger.info(
|
||||
f"移动 {source_path}/{img_id}.jpg ---> {destination_path}/{des_max_id} 移动成功"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
from nonebot import on_command, on_keyword, 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 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 configs.config import Config
|
||||
from utils.manager import group_manager, withdraw_message_manager
|
||||
import random
|
||||
import os
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
__zx_plugin_name__ = "发送本地图库图片"
|
||||
__plugin_usage__ = f"""
|
||||
usage:
|
||||
发送指定图库下的随机或指定id图片
|
||||
指令:
|
||||
{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,
|
||||
"cmd": ["发送图片"] + Config.get_config("image_management", "IMAGE_DIR_LIST"),
|
||||
}
|
||||
__plugin_task__ = {"pa": "丢人爬"}
|
||||
__plugin_resources__ = {
|
||||
"pa": IMAGE_PATH
|
||||
}
|
||||
|
||||
_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"
|
||||
|
||||
|
||||
@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"]) + "/"
|
||||
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 length == 0:
|
||||
logger.warning(f"图库 {path} 为空,调用取消!")
|
||||
await send_img.finish("该图库中没有图片噢")
|
||||
index = img_id if img_id else str(random.randint(0, length))
|
||||
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)
|
||||
if result:
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送{path}:"
|
||||
+ result
|
||||
)
|
||||
msg_id = await send_img.send(f"id:{index}" + result)
|
||||
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 "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送 {path} 失败"
|
||||
)
|
||||
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
|
||||
if _flmt.check(event.user_id):
|
||||
_flmt.start_cd(event.user_id)
|
||||
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
|
||||
@@ -3,7 +3,7 @@ from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
|
||||
from configs.config import IMAGE_DIR_LIST, UPLOAD_IMG_LEVEL
|
||||
from configs.config import Config
|
||||
from utils.utils import get_message_imgs, get_message_text
|
||||
from .data_source import upload_image_to_local
|
||||
|
||||
@@ -23,7 +23,7 @@ __plugin_des__ = "指定图库图片上传"
|
||||
__plugin_cmd__ = ["上传图片 [图库] [图片]", "连续上传图片 [图库]", "查看公开图库"]
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {"admin_level": UPLOAD_IMG_LEVEL}
|
||||
__plugin_settings__ = {"admin_level": Config.get_config("image_management", "DELETE_IMAGE_LEVEL")}
|
||||
|
||||
upload_img = on_command("上传图片", rule=to_me(), priority=5, block=True)
|
||||
|
||||
@@ -35,7 +35,7 @@ show_gallery = on_command("查看公开图库", priority=1, block=True)
|
||||
@show_gallery.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
x = '公开图库列表:\n'
|
||||
for i, e in enumerate(IMAGE_DIR_LIST):
|
||||
for i, e in enumerate(Config.get_config("image_management", "IMAGE_DIR_LIST")):
|
||||
x += f'\t{i+1}.{e}\n'
|
||||
await show_gallery.send(x[:-1])
|
||||
|
||||
@@ -46,7 +46,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if msg in ["取消", "算了"]:
|
||||
await upload_img.finish("已取消操作..", at_sender=True)
|
||||
if state["_current_key"] in ["path"]:
|
||||
if msg not in IMAGE_DIR_LIST:
|
||||
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"]:
|
||||
@@ -60,7 +60,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
raw_arg = get_message_text(event.json())
|
||||
img_list = get_message_imgs(event.json())
|
||||
if raw_arg:
|
||||
if raw_arg in IMAGE_DIR_LIST:
|
||||
if raw_arg in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = raw_arg
|
||||
if img_list:
|
||||
state["imgs"] = img_list
|
||||
@@ -88,7 +88,7 @@ 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 IMAGE_DIR_LIST:
|
||||
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:
|
||||
@@ -104,7 +104,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
@continuous_upload_img.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
path = get_message_imgs(event.json())
|
||||
if path in IMAGE_DIR_LIST:
|
||||
if path in Config.get_config("image_management", "IMAGE_DIR_LIST"):
|
||||
state["path"] = path
|
||||
await continuous_upload_img.send("图来!!")
|
||||
state["tmp"] = []
|
||||
|
||||
Reference in New Issue
Block a user