zzcore add mid && update lsp to support more key

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

View file

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

View file

@ -19,9 +19,9 @@ while(inp):
Ans_ = emmm.Ans
de(Ans_)
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()
except Exception as e:
Message = ' Error:\n'+str(e)
print(Message)
inp = input('>')
inp = input('>')

View file

@ -1,47 +1,77 @@
from zzcore import StdAns, mysakuya
import requests
from config import LOLIKEY
from config import LOLIKEYS
class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
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()
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
keys = LOLIKEYS
try:
nowkey = int(self.DATAGET()['nowkey'])
except:
nowkey = 0
if len(self.parms) < 2:
keyword = ''
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']
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl
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)
msg = '[CQ:reply,id=' + str(self.raw_msg['message_id']) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了'
return msg
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
try:
resp = requests.get(url=url,params=params).json()
except:
return -1, -1 ,''
#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}秒'
if resp['code'] == 0:
quota = resp['quota']
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 = '汝不被允许呢.'
RoleNotAllow = '汝的角色不被允许哦.'
def __init__(self,parms,uid,gid,role,raw_msg):
def __init__(self,parms,uid,gid,role,mid,raw_msg):
self.parms = parms
self.uid = uid
self.gid = gid
self.role = role
self.mid = mid
self.raw_msg = raw_msg
def DATAGET(self):
@ -86,4 +87,4 @@ def DM(msgid):
'access_token' : AUTHORIZATION,
'message_id' : msgid,
}
requests.get(url = url, params=data)
requests.get(url = url, params=data)