summaryrefslogtreecommitdiff
path: root/ATRI/plugins/pixiv.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-08-18 22:47:39 +0800
committerKyomotoi <[email protected]>2020-08-18 22:47:39 +0800
commit0d3d479a9b98aab47fb84ce0f5eadff17ff5d046 (patch)
treef57fb390c6155060d8119b6f1d2895e2aa07fb8e /ATRI/plugins/pixiv.py
parent636a16033ccb426a888e4f8a7d411e5fcb68faf2 (diff)
downloadATRI-0d3d479a9b98aab47fb84ce0f5eadff17ff5d046.tar.gz
ATRI-0d3d479a9b98aab47fb84ce0f5eadff17ff5d046.tar.bz2
ATRI-0d3d479a9b98aab47fb84ce0f5eadff17ff5d046.zip
[Update]
Diffstat (limited to 'ATRI/plugins/pixiv.py')
-rw-r--r--ATRI/plugins/pixiv.py355
1 files changed, 196 insertions, 159 deletions
diff --git a/ATRI/plugins/pixiv.py b/ATRI/plugins/pixiv.py
index 717c54a..58a2203 100644
--- a/ATRI/plugins/pixiv.py
+++ b/ATRI/plugins/pixiv.py
@@ -2,6 +2,7 @@ import time
import json
from datetime import datetime
from random import choice
+from pathlib import Path
import nonebot
from nonebot import on_command, CommandSession
@@ -41,201 +42,237 @@ def now_time():
@on_command('pixiv_seach_img', aliases = ['p站搜图', 'P站搜图', '批站搜图'], only_to_me = False)
async def _(session: CommandSession):
user = session.event.user_id
- if 0 <= now_time() < 5.5:
- await session.send(
- choice(
- [
- 'zzzz......',
- 'zzzzzzzz......',
- 'zzz...好涩哦..zzz....',
- '别...不要..zzz..那..zzz..',
- '嘻嘻..zzz..呐~..zzzz..'
- ]
- )
- )
- else:
- with open('ATRI/plugins/noobList/noobList.json', 'r') as f:
+ group = session.event.group_id
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json', 'r') as f:
data = json.load(f)
-
- if str(user) in data.keys():
+ except:
+ data = {}
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json', 'r') as f:
+ data1 = json.load(f)
+ except:
+ data1 = {}
+
+ if str(group) in data.keys():
+ pass
+ else:
+ if str(user) in data1.keys():
pass
else:
- with open('ATRI/plugins/switch/switch.json', 'r') as f:
- data = json.load(f)
-
- if data["pixiv_seach_img"] == "on":
- pid = session.current_arg.strip()
-
- if not pid:
- pid = session.get('message', prompt = '请告诉ATRI需要查询的Pid码')
-
- start =time.perf_counter()
- await session.send('开始P站搜图\n如搜索时间过长或许为图片过大上传较慢')
-
- URL = URL_1 + pid
-
- dc = json.loads(response.request_api(URL))
-
- if not dc:
- session.finish('ATRI在网络上走散了...请重试...')
-
- img = f'https://pixiv.cat/{pid}.jpg'
-
-
- end = time.perf_counter()
-
+ if 0 <= now_time() < 5.5:
await session.send(
- IMG_SEACH_REPLY.format(
- user = user,
- pid = pid,
- title = dc["response"][0]["title"],
- width = dc["response"][0]["width"],
- height = dc["response"][0]["height"],
- tags = dc["response"][0]["tags"],
- account = dc["response"][0]["user"]["account"],
- name = dc["response"][0]["user"]["name"],
- user_link = f'https://www.pixiv.net/users/' + f'{dc["response"][0]["user"]["id"]}',
- img = img,
- time = round(end - start, 3)
+ choice(
+ [
+ 'zzzz......',
+ 'zzzzzzzz......',
+ 'zzz...好涩哦..zzz....',
+ '别...不要..zzz..那..zzz..',
+ '嘻嘻..zzz..呐~..zzzz..'
+ ]
)
)
-
else:
- await session.send('该功能已被禁用...')
+ with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:
+ data = json.load(f)
+
+ if data["pixiv_seach_img"] == "on":
+ pid = session.current_arg.strip()
+
+ if not pid:
+ pid = session.get('message', prompt = '请告诉ATRI需要查询的Pid码')
+
+ start =time.perf_counter()
+ await session.send('开始P站搜图\n如搜索时间过长或许为图片过大上传较慢')
+
+ URL = URL_1 + pid
+
+ dc = json.loads(response.request_api(URL))
+
+ if not dc:
+ session.finish('ATRI在网络上走散了...请重试...')
+
+ img = f'https://pixiv.cat/{pid}.jpg'
+
+
+ end = time.perf_counter()
+
+ await session.send(
+ IMG_SEACH_REPLY.format(
+ user = user,
+ pid = pid,
+ title = dc["response"][0]["title"],
+ width = dc["response"][0]["width"],
+ height = dc["response"][0]["height"],
+ tags = dc["response"][0]["tags"],
+ account = dc["response"][0]["user"]["account"],
+ name = dc["response"][0]["user"]["name"],
+ user_link = f'https://www.pixiv.net/users/' + f'{dc["response"][0]["user"]["id"]}',
+ img = img,
+ time = round(end - start, 3)
+ )
+ )
+
+ else:
+ await session.send('该功能已被禁用...')
@on_command('pixiv_seach_author', aliases = ['画师', '搜索画师', '画师搜索'], only_to_me = False)
async def _(session: CommandSession):
user = session.event.user_id
- if 0 <= now_time() < 5.5:
- await session.send(
- choice(
- [
- 'zzzz......',
- 'zzzzzzzz......',
- 'zzz...好涩哦..zzz....',
- '别...不要..zzz..那..zzz..',
- '嘻嘻..zzz..呐~..zzzz..'
- ]
- )
- )
- else:
- with open('ATRI/plugins/noobList/noobList.json', 'r') as f:
+ group = session.event.group_id
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json', 'r') as f:
data = json.load(f)
-
- if str(user) in data.keys():
+ except:
+ data = {}
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json', 'r') as f:
+ data1 = json.load(f)
+ except:
+ data1 = {}
+
+ if str(group) in data.keys():
+ pass
+ else:
+ if str(user) in data1.keys():
pass
else:
- with open('ATRI/plugins/switch/switch.json', 'r') as f:
- data = json.load(f)
-
- if data["pixiv_seach_author"] == "on":
- author_id = session.current_arg.strip()
-
- if not author_id:
- author_id = session.get('message', prompt = '请告诉ATRI需要查询的画师ID')
-
- start =time.perf_counter()
- await session.send(f'开始获取画师{author_id}的前三项作品\n如获取时间过长或许为图片过大上传较慢')
-
- URL = URL_2 + author_id
-
- dc = json.loads(response.request_api(URL))
-
- if not dc:
- session.finish('ATRI在网络上走散了...请重试...')
-
- d ={}
-
- for i in range(0,3):
- pid = dc["response"][i]["id"]
- pidURL = f'https://pixiv.cat/{pid}.jpg'
- d[i] = [f'{pid}',f'{pidURL}']
-
- msg0 = (f'[CQ:at,qq={user}]\n画师id:{author_id},接下来展示前三作品')
-
- result = sorted(
- d.items(),
- key = lambda x:x[1],
- reverse = True
+ if 0 <= now_time() < 5.5:
+ await session.send(
+ choice(
+ [
+ 'zzzz......',
+ 'zzzzzzzz......',
+ 'zzz...好涩哦..zzz....',
+ '别...不要..zzz..那..zzz..',
+ '嘻嘻..zzz..呐~..zzzz..'
+ ]
+ )
)
+ else:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:
+ data = json.load(f)
+
+ if data["pixiv_seach_author"] == "on":
+ author_id = session.current_arg.strip()
+
+ if not author_id:
+ author_id = session.get('message', prompt = '请告诉ATRI需要查询的画师ID')
+
+ start =time.perf_counter()
+ await session.send(f'开始获取画师{author_id}的前三项作品\n如获取时间过长或许为图片过大上传较慢')
+
+ URL = URL_2 + author_id
+
+ dc = json.loads(response.request_api(URL))
+
+ if not dc:
+ session.finish('ATRI在网络上走散了...请重试...')
+
+ d ={}
+
+ for i in range(0,3):
+ pid = dc["response"][i]["id"]
+ pidURL = f'https://pixiv.cat/{pid}.jpg'
+ d[i] = [f'{pid}',f'{pidURL}']
+
+ msg0 = (f'[CQ:at,qq={user}]\n画师id:{author_id},接下来展示前三作品')
+
+ result = sorted(
+ d.items(),
+ key = lambda x:x[1],
+ reverse = True
+ )
- t = 0
+ t = 0
- for i in result:
- t += 1
- msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
- msg0 += msg
- end = time.perf_counter()
+ for i in result:
+ t += 1
+ msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
+ msg0 += msg
+ end = time.perf_counter()
- msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
- msg0 += msg1
+ msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
+ msg0 += msg1
+
+ await session.send(msg0)
- await session.send(msg0)
-
- else:
- await session.send('该功能已被禁用...')
+ else:
+ await session.send('该功能已被禁用...')
@on_command('pixiv_daily_rank', aliases = ['P站排行榜', '批站排行榜', 'p站排行榜'], only_to_me = False)
async def _(session: CommandSession):
user = session.event.user_id
- if 0 <= now_time() < 5.5:
- await session.send(
- choice(
- [
- 'zzzz......',
- 'zzzzzzzz......',
- 'zzz...好涩哦..zzz....',
- '别...不要..zzz..那..zzz..',
- '嘻嘻..zzz..呐~..zzzz..'
- ]
- )
- )
- else:
- with open('ATRI/plugins/noobList/noobList.json', 'r') as f:
+ group = session.event.group_id
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json', 'r') as f:
data = json.load(f)
-
- if str(user) in data.keys():
+ except:
+ data = {}
+ try:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json', 'r') as f:
+ data1 = json.load(f)
+ except:
+ data1 = {}
+
+ if str(group) in data.keys():
+ pass
+ else:
+ if str(user) in data1.keys():
pass
else:
- with open('ATRI/plugins/switch/switch.json', 'r') as f:
- data = json.load(f)
+ if 0 <= now_time() < 5.5:
+ await session.send(
+ choice(
+ [
+ 'zzzz......',
+ 'zzzzzzzz......',
+ 'zzz...好涩哦..zzz....',
+ '别...不要..zzz..那..zzz..',
+ '嘻嘻..zzz..呐~..zzzz..'
+ ]
+ )
+ )
+ else:
+ with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:
+ data = json.load(f)
- if data["pixiv_daily_rank"] == "on":
+ if data["pixiv_daily_rank"] == "on":
- await session.send('ATRI正在获取P站每日排行榜前五作品...')
+ await session.send('ATRI正在获取P站每日排行榜前五作品...')
- start =time.perf_counter()
- dc = json.loads(response.request_api(URL_3))
+ start =time.perf_counter()
+ dc = json.loads(response.request_api(URL_3))
- d = {}
+ d = {}
- for i in range(0,5):
- pid = dc["response"][0]["works"][i]["work"]["id"]
- pidURL = f'https://pixiv.cat/{pid}.jpg'
- d[i] = [f'{pid}',f'{pidURL}']
+ for i in range(0,5):
+ pid = dc["response"][0]["works"][i]["work"]["id"]
+ pidURL = f'https://pixiv.cat/{pid}.jpg'
+ d[i] = [f'{pid}',f'{pidURL}']
- msg0 = (f'[CQ:at,qq={user}]')
+ msg0 = (f'[CQ:at,qq={user}]')
- result = sorted(
- d.items(),
- key = lambda x:x[1],
- reverse = True
- )
+ result = sorted(
+ d.items(),
+ key = lambda x:x[1],
+ reverse = True
+ )
- t = 0
+ t = 0
- for i in result:
- t += 1
- msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
- msg0 += msg
- end = time.perf_counter()
+ for i in result:
+ t += 1
+ msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
+ msg0 += msg
+ end = time.perf_counter()
- msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
- msg0 += msg1
+ msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
+ msg0 += msg1
- await session.send(msg0)
-
- else:
- await session.send('该功能已被禁用...') \ No newline at end of file
+ await session.send(msg0)
+
+ else:
+ await session.send('该功能已被禁用...') \ No newline at end of file