2020-08-03 15:28:59 +08:00
|
|
|
from zzcore import StdAns
|
|
|
|
|
|
|
|
from datetime import timedelta, datetime
|
2020-03-16 16:47:54 +08:00
|
|
|
import requests
|
2020-08-03 15:28:59 +08:00
|
|
|
import random
|
2020-03-16 16:47:54 +08:00
|
|
|
|
2020-03-17 14:20:21 +08:00
|
|
|
|
2020-03-16 16:47:54 +08:00
|
|
|
class Ans(StdAns):
|
2020-08-04 13:45:15 +08:00
|
|
|
NotAllowGroup = [973510746]
|
2020-08-03 15:28:59 +08:00
|
|
|
|
2020-03-16 16:47:54 +08:00
|
|
|
def GETMSG(self):
|
|
|
|
|
2020-08-03 15:28:59 +08:00
|
|
|
if len(self.parms) < 2:
|
2020-03-16 16:47:54 +08:00
|
|
|
try:
|
2020-08-03 15:28:59 +08:00
|
|
|
illust = rsearch('')
|
2020-03-16 16:47:54 +08:00
|
|
|
except Exception as e:
|
2020-08-03 15:28:59 +08:00
|
|
|
# print(e)
|
|
|
|
illust = {}
|
|
|
|
|
|
|
|
elif self.parms[1] == 'help':
|
|
|
|
msg = '/pixiv 获取昨日随机日榜\n/pixiv [关键词] 使用关键词搜索,不可以有空格哦\n/pixiv id [插画id] 获取指定插画,不可以是漫画(\n/pixiv help 展示本 help'
|
2020-03-16 16:47:54 +08:00
|
|
|
return msg
|
|
|
|
|
2021-09-22 18:07:08 +08:00
|
|
|
elif self.parms[1] == 'id':
|
2020-08-03 15:28:59 +08:00
|
|
|
try:
|
|
|
|
id = int(self.parms[2])
|
|
|
|
illust = getbyid(id)
|
|
|
|
except Exception as e:
|
|
|
|
illust = {}
|
|
|
|
|
2020-03-16 16:47:54 +08:00
|
|
|
else:
|
|
|
|
try:
|
2020-08-03 15:28:59 +08:00
|
|
|
illust = rsearch(self.parms[1])
|
2020-03-16 16:47:54 +08:00
|
|
|
except Exception as e:
|
2020-08-03 15:28:59 +08:00
|
|
|
illust = {}
|
|
|
|
|
|
|
|
if illust == {}:
|
|
|
|
msg = '[CQ:reply,id={}] 看起来什么东西出错了 >_<\n稍后再试试吧'.format(str(self.raw_msg['message_id']))
|
2021-09-22 18:07:08 +08:00
|
|
|
else:
|
2020-08-03 15:28:59 +08:00
|
|
|
imgid = str(illust['id'])
|
|
|
|
|
|
|
|
imgtitle = illust['title']
|
2021-09-22 18:07:08 +08:00
|
|
|
imgo = illust['image_urls']['original'].replace('https://i.pximg.net', 'https://i.pixiv.cat')
|
|
|
|
imgl = illust['image_urls']['large'].replace('https://i.pximg.net', 'https://i.pixiv.cat')
|
|
|
|
if self.parms[len(self.parms) - 1] == 'o':
|
2020-08-03 15:28:59 +08:00
|
|
|
imgl = imgo
|
|
|
|
|
2021-09-22 18:07:08 +08:00
|
|
|
msg = '[CQ:reply,id={}]咱帮你🔍找到了这个[CQ:image,file={}]\nid {}\ntitle {}\nurl {}'.format(
|
|
|
|
str(self.raw_msg['message_id']), imgl, imgid, imgtitle, imgo)
|
2020-08-03 15:28:59 +08:00
|
|
|
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
|
|
|
|
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev'
|
2020-06-25 19:15:16 +08:00
|
|
|
return msg
|
2020-08-03 15:28:59 +08:00
|
|
|
|
|
|
|
|
2021-09-22 18:07:08 +08:00
|
|
|
def rsearch():
|
|
|
|
r = random.randint(0, 30)
|
2020-08-03 15:28:59 +08:00
|
|
|
|
2021-09-22 18:07:08 +08:00
|
|
|
# if s == '':
|
|
|
|
url = 'https://api.obfs.dev/api/pixiv/rank'
|
|
|
|
yesterday = datetime.today() + timedelta(-1)
|
|
|
|
print(yesterday.strftime('%Y-%m-%d'))
|
|
|
|
params = {
|
|
|
|
'date': yesterday.strftime('%Y-%m-%d'),
|
|
|
|
'mode': 'day',
|
|
|
|
'page': r,
|
|
|
|
'size': 5
|
|
|
|
}
|
|
|
|
# else:
|
|
|
|
# url = 'https://api.obfs.dev/api/pixiv/illust'
|
|
|
|
# params = {
|
|
|
|
# 'id': s,
|
|
|
|
# 'illustType': 'illust',
|
|
|
|
# 'searchType': 'autoTranslate',
|
|
|
|
# 'pageSize': 1,
|
|
|
|
# 'page': r,
|
|
|
|
# 'token': ''
|
|
|
|
# }
|
2020-08-03 15:28:59 +08:00
|
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
print(r)
|
|
|
|
resp = requests.get(url=url, params=params).json()
|
2021-09-22 18:07:08 +08:00
|
|
|
# if 'data' in resp:
|
|
|
|
# if resp['illust']['type'] == 'illust':
|
|
|
|
# if s == '':
|
|
|
|
# params['page'] += 1
|
|
|
|
# continue
|
|
|
|
resp['illusts'][0]['image_urls'] = [{
|
|
|
|
'large': resp['illusts'][0]['image_urls']['large'],
|
|
|
|
'original': resp['illusts'][0]['meta_single_page']['original_image_url']
|
|
|
|
}]
|
|
|
|
# return resp['data']
|
|
|
|
return resp['illusts']
|
|
|
|
# return resp['data'][0]
|
|
|
|
# params['page'] = int(params['page'] / 2)
|
2020-08-03 15:28:59 +08:00
|
|
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
def getbyid(id):
|
2021-09-22 18:07:08 +08:00
|
|
|
url = 'https://api.obfs.dev/api/pixiv/illust'
|
2020-08-03 15:28:59 +08:00
|
|
|
params = {
|
2021-09-22 18:07:08 +08:00
|
|
|
# 'type': 'illust',
|
2020-08-03 15:28:59 +08:00
|
|
|
'id': id,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = requests.get(url=url, params=params).json()
|
|
|
|
|
|
|
|
if 'illust' in resp and resp['illust']['type'] == 'illust':
|
2021-09-22 18:07:08 +08:00
|
|
|
resp['illust']['image_urls'] = [{
|
2020-08-03 15:28:59 +08:00
|
|
|
'large': resp['illust']['image_urls']['large'],
|
|
|
|
'original': resp['illust']['meta_single_page']['original_image_url']
|
|
|
|
}]
|
|
|
|
return resp['illust']
|
|
|
|
|
|
|
|
return {}
|