summaryrefslogtreecommitdiff
path: root/ATRI/plugins/setu.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-08-02 00:29:45 +0800
committerKyomotoi <[email protected]>2020-08-02 00:29:45 +0800
commitcec3a97227dd3f9a88bbafe7f2bc96bf513f53ae (patch)
tree66033fde43c45418fcf7716d14180a611be9adc0 /ATRI/plugins/setu.py
parentb9c98687b9b25c86146b849dd40b248e13d2d136 (diff)
downloadATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.tar.gz
ATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.tar.bz2
ATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.zip
[Update] Refactor this project
Diffstat (limited to 'ATRI/plugins/setu.py')
-rw-r--r--ATRI/plugins/setu.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/ATRI/plugins/setu.py b/ATRI/plugins/setu.py
new file mode 100644
index 0000000..315803b
--- /dev/null
+++ b/ATRI/plugins/setu.py
@@ -0,0 +1,49 @@
+# -*- coding:utf-8 -*-
+import time
+import json
+import nonebot
+from nonebot import on_command, CommandSession
+
+from ATRI.modules import response # type: ignore
+
+
+bot = nonebot.get_bot()
+master = bot.config.SUPERUSERS
+apikey = bot.config.LOLICONAPI # type: ignore
+
+URL = 'https://api.lolicon.app/setu/'
+
+SETU_REPLY = """Title: {title}
+Pid: {pid}
+[CQ:image,file={setu}]
+---------------
+完成时间:{time}s"""
+
+
+@on_command('setu', aliases = ['图来'], only_to_me = False)
+async def _(session: CommandSession):
+ with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f:
+ data = json.load(f)
+
+ if data["setu"] == 0:
+ start = time.perf_counter()
+ values = {
+ "apikey": apikey,
+ "r18": "0",
+ "num": "1"
+ }
+
+ dc = json.loads(response.request_api_params(URL, values))
+ end = time.perf_counter()
+
+ await session.send(
+ SETU_REPLY.format(
+ title=dc["data"][0]["title"],
+ pid=dc["data"][0]["pid"],
+ setu=dc["data"][0]["url"],
+ time = round(end - start, 3)
+ )
+ )
+
+ else:
+ await session.send('该功能已被禁用...') \ No newline at end of file