diff options
Diffstat (limited to 'ATRI/plugins/setu/modules/main_setu.py')
-rw-r--r-- | ATRI/plugins/setu/modules/main_setu.py | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/ATRI/plugins/setu/modules/main_setu.py b/ATRI/plugins/setu/modules/main_setu.py index 649cd6a..5412e90 100644 --- a/ATRI/plugins/setu/modules/main_setu.py +++ b/ATRI/plugins/setu/modules/main_setu.py @@ -17,14 +17,18 @@ from .data_source import Hso, SIZE_REDUCE, SetuData LOLICON_URL: str = "https://api.lolicon.app/setu/" -PIXIV_URL:str = "https://api.kyomotoi.moe/api/pixiv/search?mode=exact_match_for_tags&word=" +PIXIV_URL: str = ( + "https://api.kyomotoi.moe/api/pixiv/search?mode=exact_match_for_tags&word=" +) R18_ENABLED: int = 0 USE_LOCAL_DATA: bool = False MIX_LOCAL_DATA: bool = False -setu = sv.on_regex(r"来[张点][色涩]图|[涩色]图来|想要[涩色]图|[涩色]图[Tt][Ii][Mm][Ee]", - rule=is_in_service('setu')) +setu = sv.on_regex( + r"来[张点][色涩]图|[涩色]图来|想要[涩色]图|[涩色]图[Tt][Ii][Mm][Ee]", rule=is_in_service("setu") +) + @setu.handle() async def _setu(bot: Bot, event: MessageEvent) -> None: @@ -32,31 +36,23 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: check = is_too_exciting(user, 3, hours=1) if not check: return - + await bot.send(event, "别急,在找了!") - params = { - "apikey": Setu.key, - "r18": str(R18_ENABLED), - "size1200": "true" - } + params = {"apikey": Setu.key, "r18": str(R18_ENABLED), "size1200": "true"} try: - data = json.loads(await post_bytes(LOLICON_URL, params))['data'][0] + data = json.loads(await post_bytes(LOLICON_URL, params))["data"][0] except RequestError: - raise RequestError('Request failed!') - - check = await Hso.nsfw_check(data['url']) + raise RequestError("Request failed!") + + check = await Hso.nsfw_check(data["url"]) score = "{:.2%}".format(check, 4) - + if not MIX_LOCAL_DATA: if USE_LOCAL_DATA: data = (await SetuData.get_setu())[0] # type: ignore - data = { - "pid": data[0], - "title": data[1], - "url": data[6] - } + data = {"pid": data[0], "title": data[1], "url": data[6]} if random() <= 0.1: - await bot.send(event, '我找到图了,但我发给主人了❤') + await bot.send(event, "我找到图了,但我发给主人了❤") msg = await Hso.setu(data) + f"\n由用户({user})提供" for sup in BotSelfConfig.superusers: await bot.send_private_msg(user_id=sup, message=msg) @@ -65,10 +61,7 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: else: if check >= 0.9: if random() <= 0.2: - repo = ( - "我找到图了,但我发给主人了❤\n" - f"涩值:{score}" - ) + repo = "我找到图了,但我发给主人了❤\n" f"涩值:{score}" await bot.send(event, repo) msg = await Hso.setu(data) + f"\n由用户({user})提供,涩值:{score}" for sup in BotSelfConfig.superusers: @@ -77,7 +70,7 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: await setu.finish(Message(await Hso.setu(data))) else: if random() <= 0.1: - await bot.send(event, '我找到图了,但我发给主人了❤') + await bot.send(event, "我找到图了,但我发给主人了❤") msg = await Hso.setu(data) + f"\n由用户({user})提供,涩值:{score}" for sup in BotSelfConfig.superusers: await bot.send_private_msg(user_id=sup, message=msg) @@ -86,7 +79,7 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: else: if random() <= 0.5: if random() <= 0.1: - await bot.send(event, '我找到图了,但我发给主人了❤') + await bot.send(event, "我找到图了,但我发给主人了❤") msg = await Hso.setu(data) + f"\n由用户({user})提供" for sup in BotSelfConfig.superusers: await bot.send_private_msg(user_id=sup, message=msg) @@ -94,13 +87,9 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: await setu.finish(Message(await Hso.setu(data))) else: data = (await SetuData.get_setu())[0] # type: ignore - data = { - "pid": data[0], - "title": data[1], - "url": data[6] - } + data = {"pid": data[0], "title": data[1], "url": data[6]} if random() <= 0.1: - await bot.send(event, '我找到图了,但我发给主人了❤') + await bot.send(event, "我找到图了,但我发给主人了❤") msg = await Hso.setu(data) + f"\n由用户({user})提供" for sup in BotSelfConfig.superusers: await bot.send_private_msg(user_id=sup, message=msg) @@ -108,27 +97,28 @@ async def _setu(bot: Bot, event: MessageEvent) -> None: await setu.finish(Message(await Hso.setu(data))) -key_setu = sv.on_regex(r"来[点张](.*?)的[涩色🐍]图", rule=is_in_service('setu')) +key_setu = sv.on_regex(r"来[点张](.*?)的[涩色🐍]图", rule=is_in_service("setu")) + @key_setu.handle() async def _key_setu(bot: Bot, event: MessageEvent) -> None: user = event.user_id check = is_too_exciting(user, 10, hours=1) if not check: - await setu.finish('休息一下吧❤') + await setu.finish("休息一下吧❤") await bot.send(event, "别急,在找了!") msg = str(event.message).strip() tag = re.findall(r"来[点张](.*?)的?[涩色🐍]图", msg)[0] URL = PIXIV_URL + tag - + try: - data = json.loads(await get_bytes(URL))['illusts'] + data = json.loads(await get_bytes(URL))["illusts"] except RequestError: - raise RequestError('Request msg failed!') - + raise RequestError("Request msg failed!") + if random() <= 0.1: - await bot.send(event, '我找到图了,但我发给主人了❤') + await bot.send(event, "我找到图了,但我发给主人了❤") msg = await Hso.acc_setu(data) + f"\n由用户({user})提供" for sup in BotSelfConfig.superusers: await bot.send_private_msg(user_id=sup, message=msg) @@ -136,58 +126,51 @@ async def _key_setu(bot: Bot, event: MessageEvent) -> None: await setu.finish(Message(await Hso.acc_setu(data))) -setu_config = sv.on_command(cmd='涩图设置', permission=SUPERUSER) +setu_config = sv.on_command(cmd="涩图设置", permission=SUPERUSER) + @setu_config.handle() async def _setu_config(bot: Bot, event: MessageEvent) -> None: global R18_ENABLED, SIZE_REDUCE, USE_LOCAL_DATA, MIX_LOCAL_DATA - msg = str(event.message).split(' ') + msg = str(event.message).split(" ") if msg[0] == "": - repo = ( - "可用设置如下:\n" - "启用/禁用r18\n" - "启用/禁用压缩\n" - "启用/禁用本地涩图\n" - "启用/禁用混合本地涩图" - ) + repo = "可用设置如下:\n" "启用/禁用r18\n" "启用/禁用压缩\n" "启用/禁用本地涩图\n" "启用/禁用混合本地涩图" await setu_config.finish(repo) elif msg[0] == "启用r18": R18_ENABLED = 1 - await setu_config.finish('已启用r18') + await setu_config.finish("已启用r18") elif msg[0] == "禁用r18": R18_ENABLED = 0 - await setu_config.finish('已禁用r18') + await setu_config.finish("已禁用r18") elif msg[0] == "启用压缩": SIZE_REDUCE = True - await setu_config.finish('已启用图片压缩') + await setu_config.finish("已启用图片压缩") elif msg[0] == "禁用压缩": SIZE_REDUCE = False - await setu_config.finish('已禁用图片压缩') + await setu_config.finish("已禁用图片压缩") elif msg[0] == "启用本地涩图": USE_LOCAL_DATA = True - await setu_config.finish('已启用本地涩图') + await setu_config.finish("已启用本地涩图") elif msg[0] == "禁用本地涩图": USE_LOCAL_DATA = False - await setu_config.finish('已禁用本地涩图') + await setu_config.finish("已禁用本地涩图") elif msg[0] == "启用混合本地涩图": MIX_LOCAL_DATA = True - await setu_config.finish('启用混合本地涩图') + await setu_config.finish("启用混合本地涩图") elif msg[0] == "禁用混合本地涩图": MIX_LOCAL_DATA = False - await setu_config.finish('禁用混合本地涩图') + await setu_config.finish("禁用混合本地涩图") else: - await setu_config.finish('阿!请检查拼写') + await setu_config.finish("阿!请检查拼写") not_get_se = sv.on_command("不够涩") + @not_get_se.handle() async def _not_se(bot: Bot, event: MessageEvent) -> None: user = event.user_id check = is_too_exciting(user, 1, 120) if check: - msg = choice([ - "那你来发", - "那你来发❤" - ]) + msg = choice(["那你来发", "那你来发❤"]) await not_get_se.finish(msg) |