Compare commits

...

4 commits

Author SHA1 Message Date
4adfcd316f
refactor: completely rewrite humanize_tags_from_json
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-05-18 12:17:47 +03:00
e59ff67176
change: make inline query answer more compact
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-05-18 12:17:47 +03:00
735bfdb406
feat: use LinkPreviewOptions in answer_query
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-05-18 12:17:47 +03:00
1ce708a40b
change: make return None statement explicit in format_rating
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-05-18 12:17:39 +03:00
2 changed files with 8 additions and 16 deletions

View file

@ -3,14 +3,7 @@ import re
def humanize_tags_from_json(value: str, default: str) -> str:
if value != "":
output = str()
tags = value.split()
for t in tags:
output += f"{re.sub('_\\(.*', '', t)}, "
output = output[:-2]
return output
return ", ".join([re.sub('_\\(.*', '', t) for t in value.split()])
return default
@ -28,3 +21,4 @@ def format_rating(value: str) -> str | None:
case "e":
# Negative Squared Latin Capital Letter E
return "🅴"
return None

View file

@ -1,7 +1,7 @@
from uuid import uuid4
from telegram import Update, InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent, \
InlineKeyboardMarkup
InlineKeyboardMarkup, LinkPreviewOptions
from telegram.constants import ParseMode
from telegram.ext import ContextTypes
@ -43,8 +43,7 @@ async def answer_query(update: Update, query: str, data) -> None:
title=f"ID: {query}",
description=f"{characters} ({copyrights}) drawn by {artists}",
input_message_content=InputTextMessageContent(
f"ID: <code>{query}</code> {rating}\n"
f"<s><b>{characters} ({copyrights})</b> drawn by <b>{artists}</b></s>\n"
f"<code>#{query}</code> <s><b>{characters} ({copyrights})</b> drawn by <b>{artists}</b></s> {rating}\n"
f"This post has been removed because of a takedown request or rule violation.",
parse_mode=ParseMode.HTML
)
@ -69,10 +68,9 @@ async def answer_query(update: Update, query: str, data) -> None:
description=f"{characters} ({copyrights}) drawn by {artists}",
thumbnail_url=data['preview_file_url'],
input_message_content=InputTextMessageContent(
f"ID: <code>{query}</code> {rating}\n"
f"<a href='{data['large_file_url']}'><b>{characters} ({copyrights})</b> "
f"drawn by <b>{artists}</b></a>",
parse_mode=ParseMode.HTML
f"<code>#{query}</code> <b>{characters} ({copyrights})</b> drawn by <b>{artists}</b> {rating}",
parse_mode=ParseMode.HTML,
link_preview_options=LinkPreviewOptions(url=data['large_file_url'])
),
reply_markup=InlineKeyboardMarkup(keyboard)
)
@ -88,7 +86,7 @@ async def invalid_query(update: Update, query: str) -> None:
title=f"ID: {query}",
description="Error",
input_message_content=InputTextMessageContent(
f"ID: <code>{query}</code>\n"
f"<code>#{query}</code>\n"
f"That record was not found.",
parse_mode=ParseMode.HTML
)