diff options
author | Kyomotoi <[email protected]> | 2020-11-07 13:54:57 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2020-11-07 13:54:57 +0800 |
commit | 7cae371b51a14c626ce184987eea2392e15430b9 (patch) | |
tree | a35aa21a64dad59a8dc91270d78f781dbed8953d /ATRI/plugins/plugin_pixiv | |
parent | 11e4632aaf2be56c776dbc4e9f0ad5065bb60b5f (diff) | |
download | ATRI-7cae371b51a14c626ce184987eea2392e15430b9.tar.gz ATRI-7cae371b51a14c626ce184987eea2392e15430b9.tar.bz2 ATRI-7cae371b51a14c626ce184987eea2392e15430b9.zip |
[Update]
Diffstat (limited to 'ATRI/plugins/plugin_pixiv')
-rw-r--r-- | ATRI/plugins/plugin_pixiv/__init__.py | 140 |
1 files changed, 62 insertions, 78 deletions
diff --git a/ATRI/plugins/plugin_pixiv/__init__.py b/ATRI/plugins/plugin_pixiv/__init__.py index 545e0f7..e8a66df 100644 --- a/ATRI/plugins/plugin_pixiv/__init__.py +++ b/ATRI/plugins/plugin_pixiv/__init__.py @@ -17,15 +17,15 @@ from nonebot.plugin import on_command from nonebot.adapters.cqhttp import Bot, Event from utils.utils_error import errorRepo -from utils.utils_banList import banList -from utils.utils_switch import checkSwitch from utils.utils_request import request_get - +from utils.utils_rule import check_banlist, check_switch plugin_name_0 = "pixiv-pic-search" -pixivSearchIMG = on_command('p站搜图') +pixivSearchIMG = on_command('p站搜图', + rule=check_banlist() & check_switch(plugin_name_0)) + [email protected]() # type: ignore [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) group = str(event.group_id) @@ -33,16 +33,13 @@ async def _(bot: Bot, event: Event, state: dict) -> None: state["user"] = user state["group"] = group - if banList(user, group): - if checkSwitch(plugin_name_0, group): - pid = str(event.message).strip() + pid = str(event.message).strip() - if pid: - state["pid"] = pid - else: - await pixivSearchIMG.finish(f"Service-{plugin_name_0} has been closed.") + if pid: + state["pid"] = pid [email protected]("pid", prompt="请发送目标PID码") # type: ignore + [email protected]("pid", prompt="请发送目标PID码") # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: pid = state["pid"] pid = re.findall(r"\d+", pid) @@ -61,7 +58,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None: data = json.loads(request_get(URL)) except: await pixivSearchIMG.finish(errorRepo("请求数据失败")) - + msg0 = f'[CQ:at,qq={state["user"]}]\n' msg0 += f"Search result:\n" msg0 += f"Pid: {pid}\n" @@ -77,9 +74,12 @@ async def _(bot: Bot, event: Event, state: dict) -> None: plugin_name_1 = "pixiv-author-search" -pixivSearchAuthor = on_command("p站画师") +pixivSearchAuthor = on_command("p站画师", + rule=check_banlist() + & check_switch(plugin_name_1)) [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) group = str(event.group_id) @@ -87,16 +87,13 @@ async def _(bot: Bot, event: Event, state: dict) -> None: state["user"] = user state["group"] = group - if banList(user, group): - if checkSwitch(plugin_name_1, group): - author_id = str(event.message).strip() + author_id = str(event.message).strip() + + if author_id: + state["author_id"] = author_id - if author_id: - state["author_id"] = author_id - else: - await pixivSearchAuthor.finish(f"Service-{plugin_name_1} has been closed.") [email protected]("author_id", prompt="请发送目标画师id") # type: ignore [email protected]("author_id", prompt="请发送目标画师id") # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: author_id = state["author_id"] author_id = re.findall(r"\d+", author_id) @@ -105,7 +102,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None: pass else: await pixivSearchAuthor.reject("请发送纯阿拉伯数字的画师id") - + await bot.send(event, f"别急!在搜索了!\n将展示画师[{author_id}]的前三项作品") URL = f"https://api.imjad.cn/pixiv/v1/?type=member_illust&id={author_id}" @@ -116,18 +113,14 @@ async def _(bot: Bot, event: Event, state: dict) -> None: except: await pixivSearchAuthor.finish(errorRepo("请求网络失败")) - for i in range(0,3): + for i in range(0, 3): pid = data["response"][i]["id"] IMG = f"https://pixiv.cat/{author_id}.jpg" data[i] = [f"{pid}", f"{IMG}"] - + msg0 = f'[CQ:at,qq={state["user"]}]\n' - - result = sorted( - data.items(), - key=lambda x:x[1], - reverse=True - ) + + result = sorted(data.items(), key=lambda x: x[1], reverse=True) t = 0 @@ -137,55 +130,46 @@ async def _(bot: Bot, event: Event, state: dict) -> None: msg += f"({t})\n" msg += f"Pid: {i[1][0]}\n{i[1][1]}" msg0 += msg - + await pixivSearchAuthor.finish(msg0) -plugin_name_2 = "pixiv_rank" -pixivRank = on_command("p站排行榜") +plugin_name_2 = "pixiv-rank" +pixivRank = on_command("p站排行榜", + rule=check_banlist() & check_switch(plugin_name_2)) [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) - group = str(event.group_id) - if banList(user, group): - if checkSwitch(plugin_name_2, group): - - await bot.send(event, "正在获取P站每日排行榜前五作品") - - URL = "https://api.imjad.cn/pixiv/v1/?type=rank" - data = {} - - try: - data = json.loads(request_get(URL)) - except: - await pixivRank.finish(errorRepo("网络请求失败")) - - for i in range(0,5): - pid = data["response"][0]["works"][i]["work"]["id"] - IMG = f"https://pixiv.cat/{pid}.jpg" - data[i] = [f"{pid}", f"{IMG}"] - - msg0 = f"[CQ:at,qq={user}]" - - result = sorted( - data.items(), - key=lambda x:x[1], - reverse=True - ) - - t = 0 - - for i in result: - t += 1 - msg = "\n---------------\n" - msg += f"({t})\n" - msg += f"Pid: {i[1][0]}" - msg += f"{i[1][1]}" - msg0 += msg - - await pixivRank.finish(msg0) - - else: - await pixivRank.finish(f"Service-{plugin_name_2} has been closed.")
\ No newline at end of file + await bot.send(event, "正在获取P站每日排行榜前五作品") + + URL = "https://api.imjad.cn/pixiv/v1/?type=rank" + data = {} + + try: + data = json.loads(request_get(URL)) + except: + await pixivRank.finish(errorRepo("网络请求失败")) + + for i in range(0, 5): + pid = data["response"][0]["works"][i]["work"]["id"] + IMG = f"https://pixiv.cat/{pid}.jpg" + data[i] = [f"{pid}", f"{IMG}"] + + msg0 = f"[CQ:at,qq={user}]" + + result = sorted(data.items(), key=lambda x: x[1], reverse=True) + + t = 0 + + for i in result: + t += 1 + msg = "\n---------------\n" + msg += f"({t})\n" + msg += f"Pid: {i[1][0]}" + msg += f"{i[1][1]}" + msg0 += msg + + await pixivRank.finish(msg0) |