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))
|
||||
if ma.group(1) == 'headers':
|
||||
img.headers = json.loads(str(base64.b64decode(ma.group(2)), "UTF-8"))
|
||||
elements.append(img)
|
||||
if img is not None:
|
||||
elements.append(img)
|
||||
else:
|
||||
elements.append(Image(a))
|
||||
elif element_type == 'voice':
|
||||
|
|
|
@ -51,7 +51,7 @@ async def get_url(url: str, status_code: int = False, headers: dict = None, fmt=
|
|||
if log:
|
||||
Logger.info(await req.read())
|
||||
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 hasattr(req, fmt):
|
||||
return await getattr(req, fmt)()
|
||||
|
|
|
@ -19,6 +19,8 @@ async def getb30(usercode):
|
|||
async with aiohttp.ClientSession() as session:
|
||||
url = Config("arcapi_url")
|
||||
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()
|
||||
print(a)
|
||||
loadjson = json.loads(a)
|
||||
|
|
|
@ -13,6 +13,8 @@ async def get_info(usercode):
|
|||
headers = {"User-Agent": Config('arcapi_agent')}
|
||||
try:
|
||||
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:
|
||||
return [Plain('查询失败。')]
|
||||
print(get_)
|
||||
|
|
Reference in a new issue