Refactor reactions, views, and links display in PostParser
This commit is contained in:
+12
-13
@@ -318,26 +318,25 @@ class PostParser:
|
||||
|
||||
def _reactions_views_links(self, message: Message) -> Union[str, None]:
|
||||
try:
|
||||
html_parts = []
|
||||
html_parts.append("<br>")
|
||||
parts = []
|
||||
|
||||
if reactions := getattr(message, "reactions", None): #add reactions
|
||||
if reactions := getattr(message, "reactions", None):
|
||||
reactions_html = ''
|
||||
for reaction in reactions.reactions:
|
||||
reactions_html += f'<span class="reaction">{reaction.emoji} {reaction.count}</span> '
|
||||
html_parts.append(reactions_html)
|
||||
parts.append(reactions_html.strip())
|
||||
|
||||
if views := getattr(message, "views", None): #add views
|
||||
views_html = f'<span class="views">(Views: {views})</span>'
|
||||
html_parts.append(views_html)
|
||||
if views := getattr(message, "views", None):
|
||||
views_html = f'<span class="views">{views} views</span>'
|
||||
parts.append(views_html)
|
||||
|
||||
if message.chat.username: #add links to telegram and web
|
||||
tg_link = f'<br><a href="tg://resolve?domain={message.chat.username}&post={message.id}">Open in Telegram</a>'
|
||||
html_parts.append(tg_link)
|
||||
tg_web_link = f'<br><a href="https://t.me/{message.chat.username}/{message.id}">Open in Web</a>'
|
||||
html_parts.append(tg_web_link)
|
||||
if message.chat.username:
|
||||
links = []
|
||||
links.append(f'<a href="tg://resolve?domain={message.chat.username}&post={message.id}">Open in Telegram</a>')
|
||||
links.append(f'<a href="https://t.me/{message.chat.username}/{message.id}">Open in Web</a>')
|
||||
parts.append(' '.join(links))
|
||||
|
||||
html = ' '.join(html_parts) if html_parts else None
|
||||
html = '<br>' + ' '.join(parts) if parts else None
|
||||
return html
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user