update lsp

This commit is contained in:
SiHuan 2021-05-06 20:35:46 +08:00
parent db4a384097
commit bd46f9d218

View file

@ -1,83 +1,41 @@
from zzcore import StdAns, mysakuya from zzcore import StdAns, mysakuya
import requests import requests
from config import LOLIKEYS from config import LOLIKEY
class Ans(StdAns): class Ans(StdAns):
AllowGroup = [959613860,973510746, 805197917, 343700338, 125733077, 1084566280, AllowGroup = [959613860, 973510746, 805197917, 343700338, 125733077, 1084566280,
920863253, 798595664, 655057127, 196268763, 247022495, 474907856, 940333876] 920863253, 798595664, 655057127, 196268763, 247022495, 474907856, 940333876]
def GETMSG(self): def GETMSG(self):
if len(self.parms) == 1:
keys = LOLIKEYS code, picurl = getsetu()
try:
nowkey = int(self.DATAGET()['nowkey'])
except:
nowkey = 0
if len(self.parms) < 2:
keyword = ''
else: else:
keyword = self.parms[1] keyword = self.parms[1]
if mysakuya(self, keyword) == False: if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!" return "不许你们看咲夜的涩图!!"
code, picurl = getsetu()
code, quota, picurl = getsetu(keys[nowkey], keyword) if code == 0:
return f'[CQ:reply,id={self.mid}][CQ:image,file={picurl},type=flash]'
msg = '' else:
if code == -1 or code == -2: return f'[CQ:reply,id={self.mid}] 什么东西出错了code:{code}'
msg += f'>_< 天啦喽loli 不见了 Code:{code}'
elif code == 3:
msg += '咱没查到,也有可能是Pixiv坏掉惹'
elif code == 0:
if len(self.parms) < 2 or (len(self.parms) > 2 and self.parms[2] == 'p'):
msg += f'[CQ:image,file={picurl},type=flash]'
else:
msg += f'[CQ:reply,id={self.mid}]咱帮你🔍{keyword}找到了这个\n{picurl}'
if quota == 0:
nowkey = (nowkey+1) % (len(keys))
if code == 429:
msg += f'>_< 已经没有 loli 啦帮你换到了key{nowkey},再试一下吧'
else:
msg += f'额度用光了,下次将使用 key{nowkey}'
self.DATASET({'nowkey': nowkey})
return msg
def getsetu(apikey, keyword=''): def getsetu(keyword=''):
url = 'https://api.lolicon.app/setu/' url = 'https://api.lolicon.app/setu/'
params = { params = {
'apikey': apikey, 'apikey': LOLIKEY,
'keyword': keyword,
} }
if keyword != '':
params['keyword'] = keyword
try: try:
resp = requests.get(url=url, params=params).json() resp = requests.get(url=url, params=params, timeout=5).json()
print(resp)
except: except:
return -1, -1, '' return 500, ''
#quota = str(resp['quota']) picurl = ''
#seconds = resp['quota_min_ttl']
#m, s = divmod(seconds, 60)
#h, m = divmod(m, 60)
#quota_min_ttl = f'{h}时{m}分{s}秒'
if resp['code'] == 0: if resp['code'] == 0:
quota = resp['quota'] picurl = "https://r.zjuyk.site/" + resp['data'][0]['url']
try:
picurl = resp['data'][0]['url'] return resp['code'], picurl
picurl = "https://r.zjuyk.site/" + picurl
code = 0
except:
picurl = ''
code = -3
return code, quota, picurl
elif resp['code'] == 429:
return 429, 0, ''
else:
# print(resp['code'])
return -2, -1, ''