add httpcat
This commit is contained in:
parent
7a84dde223
commit
17ff0f0b16
4 changed files with 7 additions and 2 deletions
|
@ -132,7 +132,8 @@ def match_kecode(text: str) -> List[Union[Plain, Image, Voice, Embed]]:
|
||||||
img = Image(path=ma.group(2))
|
img = Image(path=ma.group(2))
|
||||||
if ma.group(1) == 'headers':
|
if ma.group(1) == 'headers':
|
||||||
img.headers = json.loads(str(base64.b64decode(ma.group(2)), "UTF-8"))
|
img.headers = json.loads(str(base64.b64decode(ma.group(2)), "UTF-8"))
|
||||||
elements.append(img)
|
if img is not None:
|
||||||
|
elements.append(img)
|
||||||
else:
|
else:
|
||||||
elements.append(Image(a))
|
elements.append(Image(a))
|
||||||
elif element_type == 'voice':
|
elif element_type == 'voice':
|
||||||
|
|
|
@ -51,7 +51,7 @@ async def get_url(url: str, status_code: int = False, headers: dict = None, fmt=
|
||||||
if log:
|
if log:
|
||||||
Logger.info(await req.read())
|
Logger.info(await req.read())
|
||||||
if status_code and req.status != status_code:
|
if status_code and req.status != status_code:
|
||||||
raise ValueError(req.status)
|
raise ValueError(f'{str(req.status)}[Ke:Image,path=https://http.cat/{str(req.status)}.jpg]')
|
||||||
if fmt is not None:
|
if fmt is not None:
|
||||||
if hasattr(req, fmt):
|
if hasattr(req, fmt):
|
||||||
return await getattr(req, fmt)()
|
return await getattr(req, fmt)()
|
||||||
|
|
|
@ -19,6 +19,8 @@ async def getb30(usercode):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
url = Config("arcapi_url")
|
url = Config("arcapi_url")
|
||||||
async with session.get(url + "user/best30?usercode=" + usercode, headers=headers) as resp:
|
async with session.get(url + "user/best30?usercode=" + usercode, headers=headers) as resp:
|
||||||
|
if resp.status != 200:
|
||||||
|
return {'text': f'获取失败{str(resp.status)}[Ke:Image,path=https://http.cat/{str(resp.status)}.jpg]'}
|
||||||
a = await resp.text()
|
a = await resp.text()
|
||||||
print(a)
|
print(a)
|
||||||
loadjson = json.loads(a)
|
loadjson = json.loads(a)
|
||||||
|
|
|
@ -13,6 +13,8 @@ async def get_info(usercode):
|
||||||
headers = {"User-Agent": Config('arcapi_agent')}
|
headers = {"User-Agent": Config('arcapi_agent')}
|
||||||
try:
|
try:
|
||||||
get_ = await get_url(api_url + "user/info?usercode=" + usercode + '&recent=1', headers=headers, fmt='json')
|
get_ = await get_url(api_url + "user/info?usercode=" + usercode + '&recent=1', headers=headers, fmt='json')
|
||||||
|
except ValueError as e:
|
||||||
|
return [Plain('查询失败:' + str(e))]
|
||||||
except Exception:
|
except Exception:
|
||||||
return [Plain('查询失败。')]
|
return [Plain('查询失败。')]
|
||||||
print(get_)
|
print(get_)
|
||||||
|
|
Reference in a new issue