PagerMaid_Plugins_Pyro/httpcat/main.py

29 lines
1002 B
Python
Raw Normal View History

2022-09-05 06:59:42 +00:00
from io import BytesIO
from pagermaid.enums import Client, Message, AsyncClient
from pagermaid.listener import listener
2023-01-23 14:51:49 +00:00
@listener(command="httpcat", description="获取 HTTP 状态码的图片。", parameters="[http 状态码]")
2022-09-05 06:59:42 +00:00
async def httpcat(client: Client, message: Message, request: AsyncClient):
try:
code = int(message.arguments)
except ValueError:
return await message.edit("http 状态码错误。")
if code < 100 or code > 599:
return await message.edit("http 状态码错误。")
pic = await request.get(f"https://http.cat/{code}.jpg")
if pic.status_code != 200:
return await message.edit("http 状态码错误。")
io = BytesIO(pic.content)
io.name = "1.jpg"
await client.send_photo(
message.chat.id,
io,
2024-02-04 07:56:06 +00:00
reply_to_message_id=message.reply_to_message_id
2023-07-01 12:18:58 +00:00
if message.outgoing
else message.id,
2024-02-04 07:56:06 +00:00
message_thread_id=message.message_thread_id,
2023-07-01 12:18:58 +00:00
)
2022-09-05 06:59:42 +00:00
await message.safe_delete()