diff options
author | Kyomotoi <[email protected]> | 2021-07-09 13:02:51 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2021-07-09 13:02:51 +0800 |
commit | c5ea0295a8fbe24371b4ad077df495a7ea3ba4f7 (patch) | |
tree | e0b9f3ad2ed779ae961dbd24d871bb2f96b3046d /ATRI/plugins/setu | |
parent | ceeed1fc36423ded449ee6a7190163d89b5b376a (diff) | |
download | ATRI-c5ea0295a8fbe24371b4ad077df495a7ea3ba4f7.tar.gz ATRI-c5ea0295a8fbe24371b4ad077df495a7ea3ba4f7.tar.bz2 ATRI-c5ea0295a8fbe24371b4ad077df495a7ea3ba4f7.zip |
⚡️ 更换涩图url索取方式
Diffstat (limited to 'ATRI/plugins/setu')
-rw-r--r-- | ATRI/plugins/setu/data_source.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/ATRI/plugins/setu/data_source.py b/ATRI/plugins/setu/data_source.py index ba714b2..0912e25 100644 --- a/ATRI/plugins/setu/data_source.py +++ b/ATRI/plugins/setu/data_source.py @@ -7,7 +7,6 @@ from ATRI.utils import request LOLICON_URL = "https://api.lolicon.app/setu/v2" -SETU_TEMP_FORMAT = "https://pixiv.cat/{p_id}.{ext}" # 为何要这样组,因为 i.pixiv.cat 不稳定! SCHEDULER_FORMAT = """ 是{tag}哦~❤ {setu} @@ -15,9 +14,10 @@ SCHEDULER_FORMAT = """ class Setu(Service): + def __init__(self): Service.__init__(self, "涩图", "hso!", rule=is_in_service("涩图")) - + @staticmethod async def random_setu() -> tuple: """ @@ -26,14 +26,13 @@ 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) - ext = temp_data.get("ext", "jpg") - url = SETU_TEMP_FORMAT.format(p_id=p_id, ext=ext) + url = temp_data["urls"].get("original", "ignore") setu = MessageSegment.image(url) return setu, title, p_id - + @staticmethod async def tag_setu(tag: str) -> tuple: """ @@ -42,19 +41,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) - ext = temp_data.get("ext", "jpg") - url = SETU_TEMP_FORMAT.format(p_id=p_id, ext=ext) + url = temp_data["urls"].get("original", "ignore") setu = MessageSegment.image(url) return setu, title, p_id, is_ok - + @staticmethod async def scheduler() -> str: """ @@ -66,12 +64,13 @@ class Setu(Service): res = await request.get(LOLICON_URL) data: dict = await res.json() temp_data: dict = data.get("data", list())[0] - - p_id = temp_data.get("pid", 88124144) + tag = choice(temp_data.get("tags", ["女孩子"])) - ext = temp_data.get("ext", "jpg") - - url = SETU_TEMP_FORMAT.format(p_id=p_id, ext=ext) + + url = temp_data["urls"].get("original", "ignore") setu = MessageSegment.image(url) - repo = SCHEDULER_FORMAT.format(tag=tag, setu=setu) + repo = SCHEDULER_FORMAT.format( + tag=tag, + setu=setu + ) return repo |