From 06c726bc3036aa7ccb11b8c1b0d4dc1cc5a80938 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 16 May 2020 23:10:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20=E5=B0=9D=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=BE=AA=E7=8E=AF=E4=BF=AE=E5=A4=8D=E4=B8=80=E8=A8=80?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagermaid/modules/message.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pagermaid/modules/message.py b/pagermaid/modules/message.py index 5df7b91..6cd9f3d 100644 --- a/pagermaid/modules/message.py +++ b/pagermaid/modules/message.py @@ -157,7 +157,17 @@ async def feet2meter(context): description="发送一句一言") async def hitokoto(context): """ Get hitokoto.cn """ - hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8")) + hitokoto_while = 1 + try: + hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8")) + except (ValueError): + while hitokoto_while < 10: + hitokoto_while += 1 + try: + hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8")) + break + except: + continue if hitokoto_json['type'] == 'a': hitokoto_type = '动画' elif hitokoto_json['type'] == 'b': @@ -196,4 +206,4 @@ async def source(context): description="显示原始 PagerMaid 项目主页的URL。") async def site(context): """ Outputs the site URL. """ - await context.edit("https://katonkeyboard.moe/pagermaid.html") \ No newline at end of file + await context.edit("https://katonkeyboard.moe/pagermaid.html")