diff options
author | Kyomotoi <[email protected]> | 2021-07-31 16:16:47 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2021-07-31 16:16:47 +0800 |
commit | 336eb9d9e98b0bee952c27a50820dbdb350bcc03 (patch) | |
tree | 718d5349232bce0d06cc901707bdd8f478c43314 /ATRI/plugins/setu | |
parent | c485985d3be687d17168512de44ea7b744fea7cc (diff) | |
download | ATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.tar.gz ATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.tar.bz2 ATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.zip |
🔥🚚✨
- 移除:laugh.txt,需要时再拉取
- 移动控制台文件至plugins/console目录下
- 新增:
- 和管理贴贴w
- 正式的可视化前端单页
Diffstat (limited to 'ATRI/plugins/setu')
-rw-r--r-- | ATRI/plugins/setu/__init__.py | 24 | ||||
-rw-r--r-- | ATRI/plugins/setu/data_source.py | 35 |
2 files changed, 34 insertions, 25 deletions
diff --git a/ATRI/plugins/setu/__init__.py b/ATRI/plugins/setu/__init__.py index d67d75b..7eb2c61 100644 --- a/ATRI/plugins/setu/__init__.py +++ b/ATRI/plugins/setu/__init__.py @@ -12,10 +12,7 @@ _setu_flmt = FreqLimiter(120) _setu_dlmt = DailyLimiter(5) -random_setu = Setu().on_command( - "来张涩图", "来张随机涩图,冷却2分钟,每天限5张", aliases={"涩图来", "来点涩图", "来份涩图"} -) - +random_setu = Setu().on_command("来张涩图", "来张随机涩图,冷却2分钟,每天限5张", aliases={"涩图来", "来点涩图", "来份涩图"}) @random_setu.handle() async def _random_setu(bot: Bot, event: MessageEvent): @@ -24,9 +21,12 @@ async def _random_setu(bot: Bot, event: MessageEvent): await random_setu.finish() if not _setu_dlmt.check(user_id): await random_setu.finish() - + setu, title, p_id = await Setu().random_setu() - repo = f"Title: {title}\n" f"Pid: {p_id}" + repo = ( + f"Title: {title}\n" + f"Pid: {p_id}" + ) await bot.send(event, repo) msg_1 = await bot.send(event, Message(setu)) event_id = msg_1["message_id"] @@ -38,7 +38,6 @@ async def _random_setu(bot: Bot, event: MessageEvent): tag_setu = Setu().on_regex(r"来[张点丶份](.*?)的[涩色🐍]图", "根据提供的tag查找涩图") - @tag_setu.handle() async def _tag_setu(bot: Bot, event: MessageEvent): user_id = event.get_user_id() @@ -46,15 +45,18 @@ async def _tag_setu(bot: Bot, event: MessageEvent): await random_setu.finish() if not _setu_dlmt.check(user_id): await random_setu.finish() - + msg = str(event.message).strip() pattern = r"来[张点丶份](.*?)的[涩色🐍]图" tag = re.findall(pattern, msg)[0] setu, title, p_id, is_ok = await Setu().tag_setu(tag) if not is_ok: await tag_setu.finish(f"没有 {tag} 的涩图呢...") - repo_0 = f"Title: {title}\n" f"Pid: {p_id}" - + repo_0 = ( + f"Title: {title}\n" + f"Pid: {p_id}" + ) + await bot.send(event, repo_0) msg_1 = await bot.send(event, Message(setu)) event_id = msg_1["message_id"] @@ -75,6 +77,6 @@ async def _scheduler_setu(bot): message_id = msg_0["message_id"] await asyncio.sleep(60) await bot.delete_msg(message_id=message_id) - + except BaseException: pass diff --git a/ATRI/plugins/setu/data_source.py b/ATRI/plugins/setu/data_source.py index 46cf7cb..22fa69f 100644 --- a/ATRI/plugins/setu/data_source.py +++ b/ATRI/plugins/setu/data_source.py @@ -1,3 +1,5 @@ +import base64 +# from pathlib import Path from random import choice from nonebot.adapters.cqhttp import MessageSegment @@ -14,9 +16,10 @@ SCHEDULER_FORMAT = """ class Setu(Service): + def __init__(self): Service.__init__(self, "涩图", "hso!", rule=is_in_service("涩图")) - + @staticmethod async def random_setu() -> tuple: """ @@ -25,13 +28,14 @@ class Setu(Service): res = await request.get(LOLICON_URL) data: dict = await res.json() temp_data: dict = data.get("data", list())[0] - - title = temp_data.get("title", "木陰のねこ") + + title = temp_data.get("title", "木陰のねこ") p_id = temp_data.get("pid", 88124144) url = temp_data["urls"].get("original", "ignore") - setu = MessageSegment.image(url) + + setu = MessageSegment.image(url, timeout=114514) return setu, title, p_id - + @staticmethod async def tag_setu(tag: str) -> tuple: """ @@ -40,18 +44,18 @@ class Setu(Service): url = LOLICON_URL + f"?tag={tag}" res = await request.get(url) data: dict = await res.json() - + temp_data: dict = data.get("data", list())[0] if not temp_data: is_ok = False is_ok = True - - title = temp_data.get("title", "木陰のねこ") + + title = temp_data.get("title", "木陰のねこ") p_id = temp_data.get("pid", 88124144) url = temp_data["urls"].get("original", "ignore") - setu = MessageSegment.image(url) + setu = MessageSegment.image(url, timeout=114514) return setu, title, p_id, is_ok - + @staticmethod async def scheduler() -> str: """ @@ -63,10 +67,13 @@ class Setu(Service): res = await request.get(LOLICON_URL) data: dict = await res.json() temp_data: dict = data.get("data", list())[0] - + tag = choice(temp_data.get("tags", ["女孩子"])) - + url = temp_data["urls"].get("original", "ignore") - setu = MessageSegment.image(url) - repo = SCHEDULER_FORMAT.format(tag=tag, setu=setu) + setu = MessageSegment.image(url, timeout=114514) + repo = SCHEDULER_FORMAT.format( + tag=tag, + setu=setu + ) return repo |