XZZ/worker/lsp.py

51 lines
1.3 KiB
Python
Raw Permalink Normal View History

2020-08-03 15:28:59 +08:00
from zzcore import StdAns, mysakuya
import requests
2021-05-06 20:35:46 +08:00
from config import LOLIKEY
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-08-25 21:34:03 +08:00
AllowGroup = [959613860, 125733077]
2020-10-30 10:13:44 +08:00
2020-08-03 15:28:59 +08:00
def GETMSG(self):
2021-08-12 19:01:29 +08:00
if self.parms[-1] == 'p':
flash = ''
self.parms = self.parms[0:-1]
else:
flash = ',type=flash'
2021-05-06 20:35:46 +08:00
if len(self.parms) == 1:
2021-08-12 19:01:29 +08:00
code, picurl, pid = getsetu()
2020-08-03 15:28:59 +08:00
else:
keyword = self.parms[1]
if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!"
2021-08-12 19:01:29 +08:00
code, picurl, pid = getsetu(keyword)
2021-05-06 20:35:46 +08:00
if code == 0:
2021-08-12 19:03:30 +08:00
self.sendmsg(f'[CQ:reply,id={self.mid}]Pixiv ID:{pid}')
return f'[CQ:image,file={picurl}{flash}]'
2021-05-06 20:35:46 +08:00
else:
return f'[CQ:reply,id={self.mid}] 什么东西出错了code:{code}'
2020-10-30 10:13:44 +08:00
2021-05-06 20:35:46 +08:00
def getsetu(keyword=''):
url = 'https://api.lolicon.app/setu/'
params = {
2021-05-06 20:35:46 +08:00
'apikey': LOLIKEY,
'keyword': keyword,
}
2020-10-30 10:13:44 +08:00
try:
2021-05-06 20:35:46 +08:00
resp = requests.get(url=url, params=params, timeout=5).json()
except:
2021-08-12 19:01:29 +08:00
return 500, '',0
2020-10-30 10:13:44 +08:00
2021-08-12 19:11:13 +08:00
2021-05-06 20:35:46 +08:00
picurl = ''
2021-08-12 19:11:13 +08:00
pid = 0
if resp['code'] == 0:
2021-05-06 20:35:46 +08:00
picurl = "https://r.zjuyk.site/" + resp['data'][0]['url']
2021-08-12 19:11:13 +08:00
pid = resp['data'][0]['pid']
2021-05-06 20:35:46 +08:00
2021-08-12 19:11:13 +08:00
return resp['code'], picurl, pid