From aacf0cde91222a45b1111511e07368c590168a22 Mon Sep 17 00:00:00 2001 From: xmengnet <794508986@qq.com> Date: Mon, 14 Jun 2021 13:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=9B=BE=E7=89=87=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E9=97=AA=E7=85=A7=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker/lsp.py | 76 ++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/worker/lsp.py b/worker/lsp.py index a3d5d38..5cbba8f 100644 --- a/worker/lsp.py +++ b/worker/lsp.py @@ -5,77 +5,37 @@ from config import LOLIKEYS class Ans(StdAns): - AllowGroup = [874769998,596678277,794290657,204097403] + AllowGroup = [874769998, 596678277, 794290657, 204097403] def GETMSG(self): - - keys = LOLIKEYS - - try: - nowkey = int(self.DATAGET()['nowkey']) - except: - nowkey = 0 - - if len(self.parms) < 2: - keyword = '' + if len(self.parms) == 1: + code, picurl = getsetu() else: keyword = self.parms[1] if mysakuya(self, keyword) == False: return "不许你们看咲夜的涩图!!" - - code, quota, picurl = getsetu(keys[nowkey], keyword) - - msg = '' - if code == -1 or code == -2: - msg += f'>_< 天啦喽,loli 不见了 Code:{code}' - elif code == 3: - msg += '咱没查到,也有可能是Pixiv坏掉惹' - elif code == 0: - 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}' - - if quota == 0: - nowkey = (nowkey+1) % (len(keys)) - if code == 429: - msg += f'>_< 已经没有 loli 啦,帮你换到了key{nowkey},再试一下吧' - else: - msg += f'额度用光了,下次将使用 key{nowkey}' - self.DATASET({'nowkey': nowkey}) - return msg + code, picurl = getsetu(keyword) + if code == 0: + return f'[CQ:reply,id={self.mid}][CQ:image,file={picurl},type=flash]' + else: + return f'[CQ:reply,id={self.mid}] 什么东西出错了,code:{code}' -def getsetu(apikey, keyword=''): +def getsetu(keyword=''): url = 'https://api.lolicon.app/setu/' params = { - 'apikey': apikey, - 'r18': 0, + 'apikey': LOLIKEYS, + 'keyword': keyword, + 'r18': 0 } - if keyword != '': - params['keyword'] = keyword try: - resp = requests.get(url=url, params=params).json() + resp = requests.get(url=url, params=params, timeout=5).json() except: - return -1, -1, '' + return 500, '' - #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}秒' + picurl = '' if resp['code'] == 0: - 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: - # print(resp['code']) - return -2, -1, '' + picurl = "https://r.zjuyk.site/" + resp['data'][0]['url'] + + return resp['code'], picurl