fix lsp keyword search
This commit is contained in:
parent
036034e99d
commit
f685397dcd
1 changed files with 19 additions and 15 deletions
|
@ -3,12 +3,15 @@ import requests
|
||||||
|
|
||||||
from config import LOLIKEYS
|
from config import LOLIKEYS
|
||||||
|
|
||||||
|
|
||||||
class Ans(StdAns):
|
class Ans(StdAns):
|
||||||
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 247022495, 474907856, 940333876]
|
AllowGroup = [973510746, 805197917, 343700338, 125733077, 1084566280,
|
||||||
|
920863253, 798595664, 655057127, 196268763, 247022495, 474907856, 940333876]
|
||||||
|
|
||||||
def GETMSG(self):
|
def GETMSG(self):
|
||||||
|
|
||||||
keys = LOLIKEYS
|
keys = LOLIKEYS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nowkey = int(self.DATAGET()['nowkey'])
|
nowkey = int(self.DATAGET()['nowkey'])
|
||||||
except:
|
except:
|
||||||
|
@ -20,43 +23,43 @@ class Ans(StdAns):
|
||||||
keyword = self.parms[1]
|
keyword = self.parms[1]
|
||||||
if mysakuya(self, keyword) == False:
|
if mysakuya(self, keyword) == False:
|
||||||
return "不许你们看咲夜的涩图!!"
|
return "不许你们看咲夜的涩图!!"
|
||||||
|
|
||||||
code, quota, picurl = getsetu(keys[nowkey], keyword)
|
code, quota, picurl = getsetu(keys[nowkey], keyword)
|
||||||
|
|
||||||
msg = ''
|
msg = ''
|
||||||
if code == -1 or code == -2:
|
if code == -1 or code == -2:
|
||||||
msg += f'>_< 天啦喽,loli 不见了 Code:{code}'
|
msg += f'>_< 天啦喽,loli 不见了 Code:{code}'
|
||||||
elif code == 3:
|
elif code == 3:
|
||||||
msg += '咱没查到,也有可能是Pixiv坏掉惹'
|
msg += '咱没查到,也有可能是Pixiv坏掉惹'
|
||||||
elif code == 0:
|
elif code == 0:
|
||||||
if len(self.parms) < 2 or (len(self.parms > 2) and self.parms[2] == 'p'):
|
if len(self.parms) < 2 or (len(self.parms) > 2 and self.parms[2] == 'p'):
|
||||||
msg += f'[CQ:image,file={picurl}]'
|
msg += f'[CQ:image,file={picurl}]'
|
||||||
else:
|
else:
|
||||||
msg += f'[CQ:reply,id={self.mid}]咱帮你🔍{keyword}找到了这个\n{picurl}'
|
msg += f'[CQ:reply,id={self.mid}]咱帮你🔍{keyword}找到了这个\n{picurl}'
|
||||||
|
|
||||||
if quota == 0:
|
if quota == 0:
|
||||||
nowkey = (nowkey+1)%(len(keys))
|
nowkey = (nowkey+1) % (len(keys))
|
||||||
if code == 429:
|
if code == 429:
|
||||||
msg += f'>_< 已经没有 loli 啦,帮你换到了key{nowkey},再试一下吧'
|
msg += f'>_< 已经没有 loli 啦,帮你换到了key{nowkey},再试一下吧'
|
||||||
else:
|
else:
|
||||||
msg += f'额度用光了,下次将使用 key{nowkey}'
|
msg += f'额度用光了,下次将使用 key{nowkey}'
|
||||||
self.DATASET({'nowkey':nowkey})
|
self.DATASET({'nowkey': nowkey})
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def getsetu(apikey, keyword = ''):
|
def getsetu(apikey, keyword=''):
|
||||||
url = 'https://api.lolicon.app/setu/'
|
url = 'https://api.lolicon.app/setu/'
|
||||||
params = {
|
params = {
|
||||||
'apikey': apikey,
|
'apikey': apikey,
|
||||||
}
|
}
|
||||||
if keyword != '':
|
if keyword != '':
|
||||||
params['keyword'] = keyword
|
params['keyword'] = keyword
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url=url,params=params).json()
|
resp = requests.get(url=url, params=params).json()
|
||||||
except:
|
except:
|
||||||
return -1, -1 ,''
|
return -1, -1, ''
|
||||||
|
|
||||||
#quota = str(resp['quota'])
|
#quota = str(resp['quota'])
|
||||||
#seconds = resp['quota_min_ttl']
|
#seconds = resp['quota_min_ttl']
|
||||||
#m, s = divmod(seconds, 60)
|
#m, s = divmod(seconds, 60)
|
||||||
|
@ -74,4 +77,5 @@ def getsetu(apikey, keyword = ''):
|
||||||
elif resp['code'] == 429:
|
elif resp['code'] == 429:
|
||||||
return 429, 0, ''
|
return 429, 0, ''
|
||||||
else:
|
else:
|
||||||
|
# print(resp['code'])
|
||||||
return -2, -1, ''
|
return -2, -1, ''
|
||||||
|
|
Loading…
Reference in a new issue