From 4b24523fd9a2495f00a7fae24b099d6c723a7be1 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 3 Apr 2022 11:39:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20speedtest=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagermaid/modules/status.py | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/pagermaid/modules/status.py b/pagermaid/modules/status.py index 2f348eb..f1867ce 100644 --- a/pagermaid/modules/status.py +++ b/pagermaid/modules/status.py @@ -260,9 +260,11 @@ async def speedtest(context): test.download() test.upload() test.results.share() - except (ShareResultsConnectFailure, ShareResultsSubmitFailure, RuntimeError) as e: + except (ShareResultsSubmitFailure, RuntimeError) as e: await context.edit(lang('speedtest_ConnectFailure')) return + except ShareResultsConnectFailure: + pass result = test.results.dict() des = ( f"**Speedtest** \n" @@ -275,24 +277,27 @@ async def speedtest(context): f"Timestamp: `{result['timestamp']}`" ) # 开始处理图片 - data = get(result['share']).content - with open('speedtest.png', mode='wb') as f: - f.write(data) - try: - img = Image.open('speedtest.png') - c = img.crop((17, 11, 727, 389)) - c.save('speedtest.png') - except: - pass - try: - await context.client.send_file(context.chat_id, 'speedtest.png', caption=des) - except: - return - try: - remove('speedtest.png') - except: - pass - await context.delete() + if result['share']: + data = get(result['share']).content + with open('speedtest.png', mode='wb') as f: + f.write(data) + try: + img = Image.open('speedtest.png') + c = img.crop((17, 11, 727, 389)) + c.save('speedtest.png') + except: + pass + try: + await context.client.send_file(context.chat_id, 'speedtest.png', caption=des) + except: + return + try: + remove('speedtest.png') + except: + pass + await context.delete() + else: + await context.edit(des) @listener(is_plugin=False, outgoing=True, command=alias_command("connection"),