diff --git a/main.py b/main.py index 44e7d6c..7b51d51 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ from PIL import Image import httpx import redis.asyncio as aioredis from aiogram import Bot, Dispatcher -from aiogram.types import Message +from aiogram.types import Message, ParseMode from aiogram.utils import executor, exceptions import dotenv @@ -41,10 +41,16 @@ async def check_updates(): continue post = posts[i] monitored_tags = set(post.tags.flatten()) & set(tag_list) - caption = f'Monitored tags: {" ".join(monitored_tags)}\n' \ - f'Artist: {" ".join(post.tags.artist)}\n' \ - f'Character: {" ".join(post.tags.character)}\n\n' \ - f'https://e621.net/posts/{post.id}' + artist_tags = post.tags.artist + character_tags = post.tags.character + copyright_tags = post.tags.copyright + caption = '\n'.join(l for l in [ + f'Monitored tags: {" ".join(monitored_tags)}', + artist_tags and f'Artist: {" ".join(artist_tags)}', + character_tags and f'Character: {", ".join(character_tags)}', + copyright_tags and f'Copyright: {", ".join(copyright_tags)}', + f'\nhttps://e621.net/posts/{post.id}' + ] if l) if post.file.url: try: logging.warning(post.file.url) @@ -59,14 +65,16 @@ async def check_updates(): width=post.file.width, height=post.file.height, thumb=post.preview.url, - caption=caption) + caption=caption, + parse_mode=ParseMode.HTML) elif post.file.ext == 'gif': await bot.send_animation(int(os.environ['SEND_CHAT']), file, width=post.file.width, height=post.file.height, thumb=post.preview.url, - caption=caption) + caption=caption, + parse_mode=ParseMode.HTML) elif post.file.ext in ('png', 'jpg'): if post.file.size > 10000000: logging.warning('compressing') @@ -84,7 +92,8 @@ async def check_updates(): file.name = 'file.jpg' await bot.send_photo(int(os.environ['SEND_CHAT']), file, - caption=caption) + caption=caption, + parse_mode=ParseMode.HTML) await redis.sadd('e621:sent', post.id) except exceptions.TelegramAPIError as e: logging.exception(e) @@ -114,7 +123,7 @@ async def del_tag(msg: Message): await msg.reply('Tag not found') return await redis.srem('e621:subs', args) - await msg.reply(f'Tag {msg} removed') + await msg.reply(f'Tag {args} removed') @dp.message_handler(commands=['list'])