XZZ/worker/lsp.py

48 lines
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 LOLIKEY
class Ans(StdAns):
2020-08-04 13:42:26 +08:00
AllowGroup = [ 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
2020-08-03 15:28:59 +08:00
def GETMSG(self):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': LOLIKEY,
}
if len(self.parms) < 2:
try:
resp = requests.get(url=url,params=params).json()
2020-08-04 13:33:07 +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}'
2020-08-03 15:28:59 +08:00
picurl = resp['data'][0]['url']
2020-08-04 13:33:07 +08:00
msg = f"[CQ:reply,id={self.raw_msg['message_id']}][CQ:image,file={picurl}]\n剩余次数 {quota}\n距离回复元气 {quota_min_ttl}"
2020-08-03 15:28:59 +08:00
except Exception as e:
print(e)
msg = '什么东西坏掉了,大概是Pixiv吧...不可能是咱!'
return msg
else:
keyword = self.parms[1]
if mysakuya(self, keyword) == False:
return "不许你们看咲夜的涩图!!"
params['keyword'] = keyword
try:
resp = requests.get(url=url,params=params).json()
picurl = resp['data'][0]['url']
2020-08-04 13:33:07 +08:00
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl
2020-08-03 15:28:59 +08:00
if len(self.parms) > 2 and self.parms[2] == 'p' :
msg = '[CQ:image,file=' + picurl + ']'
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev')
except Exception as e:
print(e)
2020-08-04 13:33:07 +08:00
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了'
2020-08-03 15:28:59 +08:00
return msg