change tags formatting
This commit is contained in:
parent
7b8af45c0b
commit
446649fc7f
14
main.py
14
main.py
@ -10,7 +10,7 @@ from io import BytesIO
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from time import time
|
from time import time
|
||||||
from typing import List
|
from typing import List, Iterable
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
@ -38,6 +38,10 @@ dp = Dispatcher()
|
|||||||
ChatFilter = F.chat.id.in_(set(map(int, os.environ['USERS'].split(','))))
|
ChatFilter = F.chat.id.in_(set(map(int, os.environ['USERS'].split(','))))
|
||||||
|
|
||||||
|
|
||||||
|
def format_tags(tags: Iterable[str]):
|
||||||
|
return ' '.join(f'#{tag}' for tag in tags) or 'None'
|
||||||
|
|
||||||
|
|
||||||
async def send_post(post: E621Post, tag_list: List[str]):
|
async def send_post(post: E621Post, tag_list: List[str]):
|
||||||
await bot.send_chat_action(int(os.environ['SEND_CHAT']), action=ChatAction.TYPING)
|
await bot.send_chat_action(int(os.environ['SEND_CHAT']), action=ChatAction.TYPING)
|
||||||
monitored_tags = set(post.tags.flatten()) & set(tag_list)
|
monitored_tags = set(post.tags.flatten()) & set(tag_list)
|
||||||
@ -45,10 +49,10 @@ async def send_post(post: E621Post, tag_list: List[str]):
|
|||||||
character_tags = post.tags.character
|
character_tags = post.tags.character
|
||||||
copyright_tags = post.tags.copyright
|
copyright_tags = post.tags.copyright
|
||||||
caption = '\n'.join(l for l in [
|
caption = '\n'.join(l for l in [
|
||||||
f'Monitored tags: <b>{" ".join(monitored_tags) or "None"}</b>',
|
f'Monitored tags: <b>{format_tags(monitored_tags) or "None"}</b>',
|
||||||
artist_tags and f'Artist: <b>{" ".join(artist_tags)}</b>',
|
artist_tags and f'Artist: <b>{format_tags(artist_tags)}</b>',
|
||||||
character_tags and f'Character: <b>{", ".join(character_tags)}</b>',
|
character_tags and f'Character: <b>{format_tags(character_tags)}</b>',
|
||||||
copyright_tags and f'Copyright: <b>{", ".join(copyright_tags)}</b>',
|
copyright_tags and f'Copyright: <b>{format_tags(copyright_tags)}</b>',
|
||||||
f'\nhttps://e621.net/posts/{post.id}'
|
f'\nhttps://e621.net/posts/{post.id}'
|
||||||
] if l)
|
] if l)
|
||||||
if post.file.url:
|
if post.file.url:
|
||||||
|
Loading…
Reference in New Issue
Block a user