From 446649fc7f1057b6ec745091903ad8eae931cf10 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Fri, 3 Nov 2023 14:32:23 +0300 Subject: [PATCH] change tags formatting --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index ca4ee9b..87721f9 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ from io import BytesIO from pathlib import Path from tempfile import TemporaryDirectory from time import time -from typing import List +from typing import List, Iterable import boto3 import ffmpeg @@ -38,6 +38,10 @@ dp = Dispatcher() 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]): await bot.send_chat_action(int(os.environ['SEND_CHAT']), action=ChatAction.TYPING) 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 copyright_tags = post.tags.copyright caption = '\n'.join(l for l in [ - f'Monitored tags: {" ".join(monitored_tags) or "None"}', - 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'Monitored tags: {format_tags(monitored_tags) or "None"}', + artist_tags and f'Artist: {format_tags(artist_tags)}', + character_tags and f'Character: {format_tags(character_tags)}', + copyright_tags and f'Copyright: {format_tags(copyright_tags)}', f'\nhttps://e621.net/posts/{post.id}' ] if l) if post.file.url: