From 5aff21aab2ef3015c41ee82fd36088e304933a89 Mon Sep 17 00:00:00 2001 From: sean <819165594@qq.com> Date: Tue, 7 Mar 2023 22:50:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E4=BC=9A=E5=8F=91=E5=87=BA=E4=B8=A4?= =?UTF-8?q?=E5=BC=A0=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98=202.=20?= =?UTF-8?q?=E9=99=90=E5=88=B6=E8=89=B2=E5=9B=BE=E8=BF=9E=E5=8F=91=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=95=B0=E9=87=8F=203.=20=E8=BF=9E=E5=8F=91=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E6=96=B0=E5=A2=9E=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/send_setu_/send_setu/__init__.py | 27 ++++++++++++++++----- plugins/send_setu_/send_setu/data_source.py | 6 ++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/send_setu_/send_setu/__init__.py b/plugins/send_setu_/send_setu/__init__.py index cc693bbb..fea7a114 100755 --- a/plugins/send_setu_/send_setu/__init__.py +++ b/plugins/send_setu_/send_setu/__init__.py @@ -1,5 +1,4 @@ import random -import re from typing import Any, Optional, Tuple, Type from nonebot import on_command, on_regex @@ -52,14 +51,15 @@ usage: 色图 *[tags]: 在线搜索指定tag色图 色图r *[tags]: 同上 [1-9]张涩图: 本地随机色图连发 - [1-9]张[tags]的涩图: 指定tag色图连发 + [1-9]张[tags]的涩图: 在线搜索指定tag色图连发 + [1-9]张涩图r[tags]: 同上 示例:色图 萝莉|少女 白丝|黑丝 示例:色图 萝莉 猫娘 注: tag至多取前20项,| 为或,萝莉|少女=萝莉或者少女 """.strip() __plugin_des__ = "不要小看涩图啊混蛋!" -__plugin_cmd__ = ["色图 ?[id]", "色图 ?[tags]", "色图r ?[tags]", "[1-9]张?[tags]色图"] +__plugin_cmd__ = ["色图 ?[id]", "色图 ?[tags]", "色图r ?[tags]", "[1-9]张?[tags]色图", "[1-9]张色图?[tags]"] __plugin_type__ = ("来点好康的",) __plugin_version__ = 0.1 __plugin_author__ = "HibiKier" @@ -117,6 +117,12 @@ __plugin_configs__ = { "default_value": None, "type": int, }, + "MAX_ONCE_NUM": { + "value": 10, + "help": "单次发送图片数量限制", + "default_value": 10, + "type": int, + }, } Config.add_plugin_config("pixiv", "PIXIV_NGINX_URL", "i.pixiv.re", help_="Pixiv反向代理") @@ -147,7 +153,7 @@ setu = on_command( "色图", aliases={"涩图", "不够色", "来一发", "再来点", "色图r"}, priority=5, block=True ) -setu_reg = on_regex("(.*)[份|发|张|个|次|点](.*)[瑟|色|涩]图$", priority=5, block=True) +setu_reg = on_regex("(.*)[份|发|张|个|次|点](.*)[瑟|色|涩]图(r?)(.*)$", priority=5, block=True) @setu.handle() @@ -228,7 +234,7 @@ async def _(bot: Bot, event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGro luox = get_luoxiang(impression) if luox: await setu.finish(luox, at_sender=True) - num, tags = reg_group + num, tags, r18, tags2 = reg_group num = num or 1 tags = tags[:-1] if tags and tags[-1] == "的" else tags if num_key.get(num): @@ -237,7 +243,16 @@ async def _(bot: Bot, event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGro num = int(num) except ValueError: num = 1 - await send_setu_handle(bot, setu_reg, event, "色图", tags, num, False) + if r18 and not Config.get_config("send_setu", "ALLOW_GROUP_R18"): + await setu.finish( + random.choice(["这种不好意思的东西怎么可能给这么多人看啦", "羞羞脸!给我滚出克私聊!", "变态变态变态变态大变态!"]) + ) + else: + limit = Config.get_config("send_setu", "MAX_ONCE_NUM") + if limit and num > limit: + num = limit + await setu.send(f"一次只能给你看 {num} 张哦") + await send_setu_handle(bot, setu_reg, event, "色图r" if r18 else "色图", tags + " " + tags2, num, r18) async def send_setu_handle( diff --git a/plugins/send_setu_/send_setu/data_source.py b/plugins/send_setu_/send_setu/data_source.py index 4bca9e12..cc30e09c 100755 --- a/plugins/send_setu_/send_setu/data_source.py +++ b/plugins/send_setu_/send_setu/data_source.py @@ -138,7 +138,7 @@ async def check_local_exists_or_download( file = IMAGE_PATH / path_ / f"{setu_image.local_id}.jpg" if file.exists(): change_img_md5(file) - return image(f"{setu_image.local_id}.jpg", path_), 200 + return image(file), 200 return await search_online_setu(setu_image.img_url, id_, path_) @@ -200,9 +200,9 @@ def gen_message( f"id:{local_id}\n" f"title:{title}\n" f"author:{author}\n" - f"PID:{pid}\n" + image(image_path) + f"PID:{pid}\n" + (image(image_path) if img_msg else "") ) - return image(image_path) + return image(image_path) if img_msg else "" # 罗翔老师! From 429b7e38b578052da53e9c7767af5c974fd7e7d1 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Sun, 12 Mar 2023 19:54:11 +0800 Subject: [PATCH 2/2] Update data_source.py --- plugins/send_setu_/send_setu/data_source.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/send_setu_/send_setu/data_source.py b/plugins/send_setu_/send_setu/data_source.py index cc30e09c..e249f160 100755 --- a/plugins/send_setu_/send_setu/data_source.py +++ b/plugins/send_setu_/send_setu/data_source.py @@ -187,7 +187,7 @@ async def get_setu_list( # 初始化消息 def gen_message( - setu_image: Setu, img_msg: bool = False + setu_image: Setu ) -> Union[Message, MessageSegment]: local_id = setu_image.local_id title = setu_image.title @@ -200,9 +200,9 @@ def gen_message( f"id:{local_id}\n" f"title:{title}\n" f"author:{author}\n" - f"PID:{pid}\n" + (image(image_path) if img_msg else "") + f"PID:{pid}\n" + image(image_path) ) - return image(image_path) if img_msg else "" + return image(image_path) # 罗翔老师!