diff --git a/main.py b/main.py index 490d5a8..444aae7 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ import asyncio import logging import os +from io import BytesIO +import httpx import redis.asyncio as aioredis from aiogram import Bot, Dispatcher from aiogram.types import Message @@ -41,17 +43,21 @@ async def check_updates(): if post.file.url: try: logging.warning(post.file.url) - if post.file.ext == 'webm': - await bot.send_video(int(os.environ['SEND_CHAT']), - post.file.url, - width=post.file.width, - height=post.file.height, - thumb=post.preview.url, - caption=caption) - else: - await bot.send_photo(int(os.environ['SEND_CHAT']), - post.file.url, - caption=caption) + async with httpx.AsyncClient() as client: + io = BytesIO() + file = io.write((await client.get(post.file.url)).content) + file.name = f'file.{post.file.ext}' + if post.file.ext == 'webm': + await bot.send_video(int(os.environ['SEND_CHAT']), + file, + width=post.file.width, + height=post.file.height, + thumb=post.preview.url, + caption=caption) + else: + await bot.send_photo(int(os.environ['SEND_CHAT']), + file, + caption=caption) await redis.sadd('e621:sent', post.id) except exceptions.TelegramAPIError as e: logging.exception(e)