From 9c1228c801abd559fb2f3cd8cba47f8000902419 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 1 Sep 2022 20:30:34 +0800 Subject: [PATCH] all fix a bug --- hitokoto/main.py | 8 ++++---- netease_comment/main.py | 6 +++--- speed_test/main.py | 10 +++++----- weather_lite/main.py | 7 ++++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hitokoto/main.py b/hitokoto/main.py index 8916e79..be1d9b8 100644 --- a/hitokoto/main.py +++ b/hitokoto/main.py @@ -1,20 +1,20 @@ from pagermaid.listener import listener -from pagermaid.single_utils import Message +from pagermaid.enums import Message, AsyncClient from pagermaid.utils import lang @listener(command="hitokoto", description=lang('hitokoto_des')) -async def hitokoto(message: Message): +async def hitokoto(request: AsyncClient, message: Message): hitokoto_while = 1 hitokoto_json = None try: - hitokoto_json = (await message.request.get("https://v1.hitokoto.cn/?charset=utf-8")).json() + hitokoto_json = (await request.get("https://v1.hitokoto.cn/?charset=utf-8")).json() except ValueError: while hitokoto_while < 10: hitokoto_while += 1 try: - hitokoto_json = (await message.request.get("https://v1.hitokoto.cn/?charset=utf-8")).json() + hitokoto_json = (await request.get("https://v1.hitokoto.cn/?charset=utf-8")).json() break except Exception: continue diff --git a/netease_comment/main.py b/netease_comment/main.py index d34d2db..b7ac0bc 100644 --- a/netease_comment/main.py +++ b/netease_comment/main.py @@ -1,13 +1,13 @@ from pagermaid.listener import listener -from pagermaid.single_utils import Message +from pagermaid.enums import Message, AsyncClient @listener(command="netease_comment", description="随机一条网易云音乐评论。") -async def netease(message: Message): +async def netease(request: AsyncClient, message: Message): for _ in range(5): try: - req = await message.request.get("https://api.66mz8.com/api/music.163.php?format=json") + req = await request.get("https://api.66mz8.com/api/music.163.php?format=json") assert req.status_code == 200 data = req.json() res = data['comments'] + '\n\n来自 @' + data[ diff --git a/speed_test/main.py b/speed_test/main.py index ab726c3..9004dce 100644 --- a/speed_test/main.py +++ b/speed_test/main.py @@ -6,7 +6,7 @@ from httpx import ReadTimeout from pagermaid.listener import listener from pagermaid.single_utils import safe_remove -from pagermaid.enums import Client, Message +from pagermaid.enums import Client, Message, AsyncClient from pagermaid.utils import lang, pip_install pip_install("speedtest-cli", alias="speedtest") @@ -31,7 +31,7 @@ def unit_convert(byte): return f"{round(byte, 2)} {units[zero]}" -async def run_speedtest(message: Message): +async def run_speedtest(request: AsyncClient, message: Message): test = Speedtest() server = int(message.arguments) if len(message.parameter) == 1 else None if server: @@ -57,7 +57,7 @@ async def run_speedtest(message: Message): f"Timestamp: `{result['timestamp']}`" ) if result["share"]: - data = await message.request.get(result["share"].replace("http:", "https:"), follow_redirects=True) + data = await request.get(result["share"].replace("http:", "https:"), follow_redirects=True) with open("speedtest.png", mode="wb") as f: f.write(data.content) with contextlib.suppress(Exception): @@ -87,7 +87,7 @@ async def get_all_ids(): @listener(command="speedtest", description=lang('speedtest_des'), parameters="(Server ID/测速点列表)") -async def speedtest(client: Client, message: Message): +async def speedtest(client: Client, message: Message, request: AsyncClient): """ Tests internet speed using speedtest. """ if message.arguments == "测速点列表": msg = message @@ -97,7 +97,7 @@ async def speedtest(client: Client, message: Message): if message.arguments == "测速点列表": des, photo = await get_all_ids() else: - des, photo = await run_speedtest(message) + des, photo = await run_speedtest(request, message) except SpeedtestHTTPError: return await msg.edit(lang('speedtest_ConnectFailure')) except ValueError: diff --git a/weather_lite/main.py b/weather_lite/main.py index 91a5fbb..fa855bb 100644 --- a/weather_lite/main.py +++ b/weather_lite/main.py @@ -1,17 +1,18 @@ from pagermaid.listener import listener -from pagermaid.single_utils import Message, safe_remove +from pagermaid.enums import Message, AsyncClient +from pagermaid.single_utils import safe_remove @listener(command="weather_lite", description="查询天气", parameters="<城市>") -async def weather_lite(message: Message): +async def weather_lite(request: AsyncClient, message: Message): if not message.arguments: return await message.edit("请输入城市名称") if message.arguments.startswith("_"): return await message.edit("请输入正确的城市名称") city = message.arguments.strip() - data = await message.request.get(f"https://zh.wttr.in/{city}.png") + data = await request.get(f"https://zh.wttr.in/{city}.png") if data.status_code != 200: return await message.edit("请输入正确的城市名称") with open("weather.png", "wb") as f: