zzcore add mid && update lsp to support more key

This commit is contained in:
SiHuan 2020-08-17 10:40:46 +08:00
parent a58e1954b7
commit 76a0548dea
4 changed files with 70 additions and 38 deletions

View file

@ -8,6 +8,7 @@ def ZZRouter(data):
uid = data['user_id'] uid = data['user_id']
gid = data['group_id'] gid = data['group_id']
role = data['sender']['role'] role = data['sender']['role']
mid = data['message_id']
parms = str.split(data['message'][1:]) parms = str.split(data['message'][1:])
print(uid, gid, role, parms) print(uid, gid, role, parms)
if parms == []: if parms == []:
@ -20,7 +21,7 @@ def ZZRouter(data):
except: except:
Ans_ = emmm.Ans Ans_ = emmm.Ans
Ans = Ans_(parms, uid, gid, role, data) Ans = Ans_(parms, uid, gid, role, mid, data)
Message = Ans.CheckPermission() Message = Ans.CheckPermission()
if Message == 0: if Message == 0:
Message = Ans.GETMSG() Message = Ans.GETMSG()

View file

@ -19,7 +19,7 @@ while(inp):
Ans_ = emmm.Ans Ans_ = emmm.Ans
de(Ans_) de(Ans_)
try: try:
Ans = Ans_(parms,uid=0,gid=0,role='owner',raw_msg={'message':'/' + inp, 'message_id' : '1001'}) Ans = Ans_(parms,uid=0,gid=0,role='owner',mid=1001, raw_msg={'message':'/' + inp, 'message_id' : '1001'})
Message = Ans.GETMSG() Message = Ans.GETMSG()
except Exception as e: except Exception as e:
Message = ' Error:\n'+str(e) Message = ' Error:\n'+str(e)

View file

@ -1,47 +1,77 @@
from zzcore import StdAns, mysakuya from zzcore import StdAns, mysakuya
import requests import requests
from config import LOLIKEY from config import LOLIKEYS
class Ans(StdAns): class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856] AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
def GETMSG(self): def GETMSG(self):
url = 'https://api.lolicon.app/setu/'
params = { keys = LOLIKEYS
'apikey': LOLIKEY,
} try:
nowkey = int(self.DATAGET()['nowkey'])
except:
nowkey = 0
if len(self.parms) < 2: if len(self.parms) < 2:
try: keyword = ''
resp = requests.get(url=url,params=params).json()
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 = resp['data'][0]['url']
msg = f"[CQ:reply,id={self.raw_msg['message_id']}][CQ:image,file={picurl}]\n剩余次数 {quota}\n距离回复元气 {quota_min_ttl}"
except Exception as e:
print(e)
msg = '什么东西坏掉了,大概是Pixiv吧...不可能是咱!'
return msg
else: else:
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)
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
def getsetu(apikey, keyword = ''):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': apikey,
}
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()
picurl = resp['data'][0]['url'] except:
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl return -1, -1 ,''
if len(self.parms) > 2 and self.parms[2] == 'p' : #quota = str(resp['quota'])
msg = '[CQ:image,file=' + picurl + ']' #seconds = resp['quota_min_ttl']
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev') #m, s = divmod(seconds, 60)
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev') #h, m = divmod(m, 60)
except Exception as e: #quota_min_ttl = f'{h}时{m}分{s}秒'
print(e) if resp['code'] == 0:
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了' quota = resp['quota']
return msg try:
picurl = resp['data'][0]['url']
code = 0
except:
picurl = ''
code = -3
return code, quota, picurl
elif resp['code'] == 429:
return 429, 0, ''
else:
return -2, -1, ''

View file

@ -12,11 +12,12 @@ class StdAns():
UserNotAllow = '汝不被允许呢.' UserNotAllow = '汝不被允许呢.'
RoleNotAllow = '汝的角色不被允许哦.' RoleNotAllow = '汝的角色不被允许哦.'
def __init__(self,parms,uid,gid,role,raw_msg): def __init__(self,parms,uid,gid,role,mid,raw_msg):
self.parms = parms self.parms = parms
self.uid = uid self.uid = uid
self.gid = gid self.gid = gid
self.role = role self.role = role
self.mid = mid
self.raw_msg = raw_msg self.raw_msg = raw_msg
def DATAGET(self): def DATAGET(self):