diff --git a/main.py b/main.py index bacec7f..e941f7d 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ import os import redis.asyncio as aioredis from aiogram import Bot, Dispatcher from aiogram.types import Message -from aiogram.utils import executor +from aiogram.utils import executor, exceptions import dotenv from e621 import E621 @@ -38,19 +38,22 @@ async def check_updates(): f'Character: {" ".join(post.tags.character)}\n\n' \ f'https://e621.net/posts/{post.id}' if post.file.url: - 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) - await redis.sadd('e621:sent', post.id) + 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) + await redis.sadd('e621:sent', post.id) + except exceptions.TelegramAPIError as e: + logging.exception(e) @dp.message_handler(commands=['add'])