From 17ff0f0b163f856d014eea6ee1cd058939ae461f Mon Sep 17 00:00:00 2001 From: yzhh <2596322644@qq.com> Date: Fri, 7 Jan 2022 23:16:28 +0800 Subject: [PATCH] add httpcat --- core/elements/message/chain.py | 3 ++- core/utils/bot.py | 2 +- modules/arcaea/getb30.py | 2 ++ modules/arcaea/info.py | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/elements/message/chain.py b/core/elements/message/chain.py index f70b0c67..d812ecfe 100644 --- a/core/elements/message/chain.py +++ b/core/elements/message/chain.py @@ -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': diff --git a/core/utils/bot.py b/core/utils/bot.py index 65bc9113..c4df6454 100644 --- a/core/utils/bot.py +++ b/core/utils/bot.py @@ -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)() diff --git a/modules/arcaea/getb30.py b/modules/arcaea/getb30.py index 9e4e916a..afc67e05 100644 --- a/modules/arcaea/getb30.py +++ b/modules/arcaea/getb30.py @@ -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) diff --git a/modules/arcaea/info.py b/modules/arcaea/info.py index d2f5d69f..c5e3a9e4 100644 --- a/modules/arcaea/info.py +++ b/modules/arcaea/info.py @@ -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_)