2020-08-03 15:28:59 +08:00
|
|
|
|
from zzcore import StdAns, mysakuya
|
|
|
|
|
import requests
|
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
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):
|
2020-10-30 10:13:44 +08:00
|
|
|
|
AllowGroup = [973510746, 805197917, 343700338, 125733077, 1084566280,
|
|
|
|
|
920863253, 798595664, 655057127, 196268763, 247022495, 474907856, 940333876]
|
|
|
|
|
|
2020-08-03 15:28:59 +08:00
|
|
|
|
def GETMSG(self):
|
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
keys = LOLIKEYS
|
2020-10-30 10:13:44 +08:00
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
try:
|
|
|
|
|
nowkey = int(self.DATAGET()['nowkey'])
|
|
|
|
|
except:
|
|
|
|
|
nowkey = 0
|
2020-08-03 15:28:59 +08:00
|
|
|
|
|
2020-08-17 10:40:46 +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
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
code, quota, picurl = getsetu(keys[nowkey], keyword)
|
2020-10-30 10:13:44 +08:00
|
|
|
|
|
2020-08-17 10:40:46 +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'):
|
2020-08-17 10:40:46 +08:00
|
|
|
|
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
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
if quota == 0:
|
2020-10-30 10:13:44 +08:00
|
|
|
|
nowkey = (nowkey+1) % (len(keys))
|
2020-08-17 10:40:46 +08:00
|
|
|
|
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})
|
2020-08-17 10:40:46 +08:00
|
|
|
|
return msg
|
2020-10-30 10:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getsetu(apikey, keyword=''):
|
2020-08-17 10:40:46 +08:00
|
|
|
|
url = 'https://api.lolicon.app/setu/'
|
|
|
|
|
params = {
|
|
|
|
|
'apikey': apikey,
|
|
|
|
|
}
|
|
|
|
|
if keyword != '':
|
|
|
|
|
params['keyword'] = keyword
|
2020-10-30 10:13:44 +08:00
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
try:
|
2020-10-30 10:13:44 +08:00
|
|
|
|
resp = requests.get(url=url, params=params).json()
|
2020-08-17 10:40:46 +08:00
|
|
|
|
except:
|
2020-10-30 10:13:44 +08:00
|
|
|
|
return -1, -1, ''
|
|
|
|
|
|
2020-08-17 10:40:46 +08:00
|
|
|
|
#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:
|
|
|
|
|
quota = resp['quota']
|
|
|
|
|
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'])
|
2020-08-17 10:40:46 +08:00
|
|
|
|
return -2, -1, ''
|