add pixiv and lsp

This commit is contained in:
SiHuan 2020-08-03 15:28:59 +08:00
parent 9d63ff3122
commit 09c9b23940
3 changed files with 139 additions and 31 deletions

View file

@ -19,7 +19,7 @@ while(inp):
Ans_ = emmm.Ans Ans_ = emmm.Ans
de(Ans_) de(Ans_)
try: try:
Ans = Ans_(parms,uid=0,gid=0,role='owner',raw_msg={'message':'/' + inp}) Ans = Ans_(parms,uid=0,gid=0,role='owner',raw_msg={'message':'/' + inp, 'message_id' : '1001'})
Message = Ans.GETMSG() Message = Ans.GETMSG()
except Exception as e: except Exception as e:
Message = ' Error:\n'+str(e) Message = ' Error:\n'+str(e)

42
worker/lsp.py Normal file
View file

@ -0,0 +1,42 @@
from zzcore import StdAns, mysakuya
import requests
from config import LOLIKEY
class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
def GETMSG(self):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': LOLIKEY,
}
if len(self.parms) < 2:
try:
resp = requests.get(url=url,params=params).json()
picurl = resp['data'][0]['url']
msg = picurl
except Exception as e:
print(e)
msg = '什么东西坏掉了,大概是Pixiv吧...不可能是咱!'
return msg
else:
keyword = self.parms[1]
if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!"
params['keyword'] = keyword
try:
resp = requests.get(url=url,params=params).json()
picurl = resp['data'][0]['url']
msg = '[CQ:at,qq=' + str(self.uid) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl
if len(self.parms) > 2 and self.parms[2] == 'p' :
msg = '[CQ:image,file=' + picurl + ']'
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev')
except Exception as e:
print(e)
msg = '[CQ:at,qq=' + str(self.uid) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了'
return msg

View file

@ -1,42 +1,108 @@
from zzcore import StdAns, mysakuya from zzcore import StdAns
import requests
from datetime import timedelta, datetime
import requests
import random
from config import LOLIKEY
class Ans(StdAns): class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
def GETMSG(self): def GETMSG(self):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': LOLIKEY,
}
if len(self.parms) < 2: if len(self.parms) < 2:
try: try:
resp = requests.get(url=url,params=params).json() illust = rsearch('')
picurl = resp['data'][0]['url']
msg = picurl
except Exception as e: except Exception as e:
print(e) # print(e)
msg = '什么东西坏掉了,大概是Pixiv吧...不可能是咱!' illust = {}
elif self.parms[1] == 'help':
msg = '/pixiv 获取昨日随机日榜\n/pixiv [关键词] 使用关键词搜索,不可以有空格哦\n/pixiv id [插画id] 获取指定插画,不可以是漫画(\n/pixiv help 展示本 help'
return msg return msg
elif self.parms[1] == 'id' :
try:
id = int(self.parms[2])
illust = getbyid(id)
except Exception as e:
illust = {}
else: else:
keyword = self.parms[1]
if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!"
params['keyword'] = keyword
try: try:
resp = requests.get(url=url,params=params).json() illust = rsearch(self.parms[1])
picurl = resp['data'][0]['url']
msg = '[CQ:at,qq=' + str(self.uid) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl
if len(self.parms) > 2 and self.parms[2] == 'p' :
msg = '[CQ:image,file=' + picurl + ']'
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev')
except Exception as e: except Exception as e:
print(e) illust = {}
msg = '[CQ:at,qq=' + str(self.uid) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了'
if illust == {}:
msg = '[CQ:reply,id={}] 看起来什么东西出错了 >_<\n稍后再试试吧'.format(str(self.raw_msg['message_id']))
else :
imgid = str(illust['id'])
imgtitle = illust['title']
imgo = illust['imageUrls'][0]['original'].replace('https://i.pximg.net','https://i.pixiv.cat')
imgl = illust['imageUrls'][0]['large'].replace('https://i.pximg.net','https://i.pixiv.cat')
if self.parms[len(self.parms)-1] == 'o':
imgl = imgo
msg = '[CQ:reply,id={}]咱帮你🔍找到了这个[CQ:image,file={}]\nid {}\ntitle {}\nurl {}'.format(str(self.raw_msg['message_id']), imgl, imgid, imgtitle, imgo)
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev'
return msg return msg
def rsearch(s):
r = random.randint(0, 233)
if s == '':
url = 'https://api.pixivic.com/ranks'
yesterday = datetime.today() + timedelta(-1)
params = {
'date' : yesterday.strftime('%Y-%m-%d') ,
'mode' : 'day',
'pageSize' : 1,
'page' : r,
}
else:
url = 'https://api.pixivic.com/illustrations'
params = {
'keyword': s,
'illustType': 'illust',
'searchType': 'autoTranslate',
'pageSize': 1,
'page': r
}
for _ in range(3):
print(r)
resp = requests.get(url=url, params=params).json()
if 'data' in resp :
if resp['data'][0]['type'] != 'illust':
params['page'] += 1
continue
return resp['data'][0]
params['page'] = int(params['page']/2)
return {}
def getbyid(id):
url = 'https://api.imjad.cn/pixiv/v2/'
params = {
'type': 'illust',
'id': id,
}
resp = requests.get(url=url, params=params).json()
if 'illust' in resp and resp['illust']['type'] == 'illust':
resp['illust']['imageUrls'] = [{
'large': resp['illust']['image_urls']['large'],
'original': resp['illust']['meta_single_page']['original_image_url']
}]
return resp['illust']
return {}