update captions
This commit is contained in:
parent
186030c70a
commit
921bf45ce5
27
main.py
27
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: <b>{" ".join(monitored_tags)}</b>',
|
||||
artist_tags and f'Artist: <b>{" ".join(artist_tags)}</b>',
|
||||
character_tags and f'Character: <b>{", ".join(character_tags)}</b>',
|
||||
copyright_tags and f'Copyright: <b>{", ".join(copyright_tags)}</b>',
|
||||
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'])
|
||||
|
Loading…
Reference in New Issue
Block a user