XZZ/worker/lsp.py

82 lines
2.2 KiB
Python
Raw Normal View History

2020-08-03 15:28:59 +08:00
from zzcore import StdAns, mysakuya
import requests
from config import LOLIKEYS
2020-08-03 15:28:59 +08:00
2020-10-30 10:13:44 +08:00
2020-08-03 15:28:59 +08:00
class Ans(StdAns):
2021-06-07 20:19:42 +08:00
AllowGroup = [874769998,596678277,794290657,204097403]
2020-10-30 10:13:44 +08:00
2020-08-03 15:28:59 +08:00
def GETMSG(self):
keys = LOLIKEYS
2020-10-30 10:13:44 +08:00
try:
nowkey = int(self.DATAGET()['nowkey'])
except:
nowkey = 0
2020-08-03 15:28:59 +08:00
if len(self.parms) < 2:
keyword = ''
2020-08-03 15:28:59 +08:00
else:
keyword = self.parms[1]
if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!"
2020-10-30 10:13:44 +08:00
code, quota, picurl = getsetu(keys[nowkey], keyword)
2020-10-30 10:13:44 +08:00
msg = ''
if code == -1 or code == -2:
msg += f'>_< 天啦喽loli 不见了 Code:{code}'
elif code == 3:
msg += '咱没查到,也有可能是Pixiv坏掉惹'
elif code == 0:
2020-10-30 10:13:44 +08:00
if len(self.parms) < 2 or (len(self.parms) > 2 and self.parms[2] == 'p'):
msg += f'[CQ:image,file={picurl}]'
else:
msg += f'[CQ:reply,id={self.mid}]咱帮你🔍{keyword}找到了这个\n{picurl}'
2020-10-30 10:13:44 +08:00
if quota == 0:
2020-10-30 10:13:44 +08:00
nowkey = (nowkey+1) % (len(keys))
if code == 429:
msg += f'>_< 已经没有 loli 啦帮你换到了key{nowkey},再试一下吧'
else:
msg += f'额度用光了,下次将使用 key{nowkey}'
2020-10-30 10:13:44 +08:00
self.DATASET({'nowkey': nowkey})
return msg
2020-10-30 10:13:44 +08:00
def getsetu(apikey, keyword=''):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': apikey,
2021-06-07 20:19:42 +08:00
'r18': 0,
}
if keyword != '':
params['keyword'] = keyword
2020-10-30 10:13:44 +08:00
try:
2020-10-30 10:13:44 +08:00
resp = requests.get(url=url, params=params).json()
except:
2020-10-30 10:13:44 +08:00
return -1, -1, ''
#quota = str(resp['quota'])
#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:
2021-06-07 20:19:42 +08:00
quota = resp['count']
try:
picurl = resp['data'][0]['url']
code = 0
except:
picurl = ''
code = -3
return code, quota, picurl
elif resp['code'] == 429:
return 429, 0, ''
else:
2020-10-30 10:13:44 +08:00
# print(resp['code'])
return -2, -1, ''