summaryrefslogtreecommitdiff
path: root/ATRI/plugins/setu
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/setu')
-rw-r--r--ATRI/plugins/setu/__init__.py33
-rw-r--r--ATRI/plugins/setu/data_source.py57
2 files changed, 58 insertions, 32 deletions
diff --git a/ATRI/plugins/setu/__init__.py b/ATRI/plugins/setu/__init__.py
index d67d75b..eec5281 100644
--- a/ATRI/plugins/setu/__init__.py
+++ b/ATRI/plugins/setu/__init__.py
@@ -25,10 +25,15 @@ async def _random_setu(bot: Bot, event: MessageEvent):
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, setu = await Setu().random_setu()
await bot.send(event, repo)
- msg_1 = await bot.send(event, Message(setu))
+
+ msg_1 = dict()
+ try:
+ msg_1 = await bot.send(event, Message(setu))
+ except Exception:
+ await random_setu.finish("hso(发不出")
+
event_id = msg_1["message_id"]
_setu_flmt.start_cd(user_id)
_setu_dlmt.increase(user_id)
@@ -50,13 +55,18 @@ async def _tag_setu(bot: Bot, event: MessageEvent):
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, setu = await Setu().tag_setu(tag)
+ if not setu:
+ await tag_setu.finish(repo)
+
+ await bot.send(event, repo)
+
+ msg_1 = dict()
+ try:
+ msg_1 = await bot.send(event, Message(setu))
+ except Exception:
+ await random_setu.finish("hso(发不出")
- await bot.send(event, repo_0)
- msg_1 = await bot.send(event, Message(setu))
event_id = msg_1["message_id"]
_setu_flmt.start_cd(user_id)
_setu_dlmt.increase(user_id)
@@ -71,10 +81,13 @@ async def _scheduler_setu(bot):
lucky_group = choice(group_list)
group_id = lucky_group["group_id"]
setu = await Setu().scheduler()
+ if not setu:
+ return
+
msg_0 = await bot.send_group_msg(group_id=int(group_id), message=Message(setu))
message_id = msg_0["message_id"]
await asyncio.sleep(60)
await bot.delete_msg(message_id=message_id)
- except BaseException:
+ except Exception:
pass
diff --git a/ATRI/plugins/setu/data_source.py b/ATRI/plugins/setu/data_source.py
index 47f76b6..2c665ae 100644
--- a/ATRI/plugins/setu/data_source.py
+++ b/ATRI/plugins/setu/data_source.py
@@ -10,10 +10,6 @@ from ATRI.utils import request
LOLICON_URL = "https://api.lolicon.app/setu/v2"
-SCHEDULER_FORMAT = """
-是{tag}哦~❤
-{setu}
-"""
class Setu(Service):
@@ -26,15 +22,19 @@ class Setu(Service):
随机涩图.
"""
res = await request.get(LOLICON_URL)
- data: dict = await res.json()
- temp_data: dict = data.get("data", list())[0]
+ data: dict = res.json()
+ temp_data: dict = data.get("data", list())
+ if not temp_data:
+ return "涩批爬", None
- title = temp_data.get("title", "木陰のねこ")
- p_id = temp_data.get("pid", 88124144)
- url = temp_data["urls"].get("original", "ignore")
+ data: dict = temp_data[0]
+ title = data.get("title", "木陰のねこ")
+ p_id = data.get("pid", 88124144)
+ url = data["urls"].get("original", "ignore")
setu = MessageSegment.image(url, timeout=114514)
- return setu, title, p_id
+ repo = f"Title: {title}\nPid: {p_id}"
+ return repo, setu
@staticmethod
async def tag_setu(tag: str) -> tuple:
@@ -43,18 +43,22 @@ class Setu(Service):
"""
url = LOLICON_URL + f"?tag={tag}"
res = await request.get(url)
- data: dict = await res.json()
+ data: dict = res.json()
- temp_data: dict = data.get("data", list())[0]
+ temp_data: dict = data.get("data", list())
if not temp_data:
- is_ok = False
- is_ok = True
+ return f"没有 {tag} 的涩图呢...", None
- title = temp_data.get("title", "木陰のねこ")
- p_id = temp_data.get("pid", 88124144)
- url = temp_data["urls"].get("original", "ignore")
+ data = temp_data[0]
+ title = data.get("title", "木陰のねこ")
+ p_id = data.get("pid", 88124144)
+ url = data["urls"].get(
+ "original",
+ "https://i.pixiv.cat/img-original/img/2021/02/28/22/44/49/88124144_p0.jpg",
+ )
setu = MessageSegment.image(url, timeout=114514)
- return setu, title, p_id, is_ok
+ repo = f"Title: {title}\nPid: {p_id}"
+ return repo, setu
@staticmethod
async def scheduler() -> str:
@@ -65,12 +69,21 @@ class Setu(Service):
{setu}
"""
res = await request.get(LOLICON_URL)
- data: dict = await res.json()
- temp_data: dict = data.get("data", list())[0]
+ data: dict = res.json()
+ temp_data: dict = data.get("data", list())
+ if not temp_data:
+ return ""
tag = choice(temp_data.get("tags", ["女孩子"]))
- url = temp_data["urls"].get("original", "ignore")
+ temp_arg = temp_data[0].get(
+ "urls",
+ "https://i.pixiv.cat/img-original/img/2021/02/28/22/44/49/88124144_p0.jpg",
+ )
+ url = temp_data[0]["urls"].get(
+ "original",
+ "https://i.pixiv.cat/img-original/img/2021/02/28/22/44/49/88124144_p0.jpg",
+ )
setu = MessageSegment.image(url, timeout=114514)
- repo = SCHEDULER_FORMAT.format(tag=tag, setu=setu)
+ repo = f"是{tag}哦~❤\n{setu}"
return repo