Compare commits

...

3 commits

Author SHA1 Message Date
fff77f51f8
fix: do not search for posts below or equal to ID 0
All checks were successful
Build / Upload to production (push) Successful in 1m46s
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-06-07 20:58:01 +03:00
8568d788db
feat: show rating on inline query
this commit also updates all query result titles

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-06-07 20:56:03 +03:00
28df00e34f
fix: rewrite message contents in inline_query.py
closes #3

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-06-07 20:43:04 +03:00

View file

@ -24,6 +24,10 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
if not query.isdigit():
return
query = int(query)
if query <= 0:
return
data = get_json(f"posts/{query}")
if data is None:
@ -33,7 +37,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
await answer_query(update, query, data)
async def answer_query(update: Update, query: str, data) -> None:
async def answer_query(update: Update, query: int, data) -> None:
characters = humanize_tags_from_json(data["tag_string_character"], "no characters")
copyrights = humanize_tags_from_json(
data["tag_string_copyright"], "unknown copyright"
@ -45,16 +49,27 @@ async def answer_query(update: Update, query: str, data) -> None:
results = [
InlineQueryResultArticle(
id=str(uuid4()),
title=f"ID: {query}",
title=f"#{query} {rating}",
description=f"{characters} ({copyrights}) drawn by {artists}",
input_message_content=InputTextMessageContent(
html_parser.code(f"#{query}")
+ html_parser.strikethrough(
f" {html_parser.bold(f"{characters} ({copyrights})")}"
f"drawn by {html_parser.bold(artists)}"
)
+ rating
+ "\nThis post has been removed because of a takedown request or rule violation.",
" ".join(
[
html_parser.code(f"#{query}"),
html_parser.strikethrough(
" ".join(
[
html_parser.bold(
f"{characters} ({copyrights})"
),
"drawn by",
html_parser.bold(artists),
]
)
),
rating,
"\nThis post has been removed because of a takedown request or rule violation.",
]
),
parse_mode=ParseMode.HTML,
),
)
@ -76,12 +91,19 @@ async def answer_query(update: Update, query: str, data) -> None:
results = [
InlineQueryResultArticle(
id=str(uuid4()),
title=f"ID: {query}",
title=f"#{query} {rating}",
description=f"{characters} ({copyrights}) drawn by {artists}",
thumbnail_url=data["preview_file_url"],
input_message_content=InputTextMessageContent(
html_parser.code(f"#{query}")
+ f" {html_parser.bold(f"{characters} ({copyrights})")} drawn by {html_parser.bold(artists)} {rating}",
" ".join(
[
html_parser.code(f"#{query}"),
html_parser.bold(f"{characters} ({copyrights})"),
"drawn by",
html_parser.bold(artists),
rating,
]
),
parse_mode=ParseMode.HTML,
link_preview_options=LinkPreviewOptions(url=data["large_file_url"]),
),
@ -92,14 +114,14 @@ async def answer_query(update: Update, query: str, data) -> None:
await update.inline_query.answer(results)
async def invalid_query(update: Update, query: str) -> None:
async def invalid_query(update: Update, query: int) -> None:
results = [
InlineQueryResultArticle(
id=str(uuid4()),
title=f"ID: {query}",
title=f"#{query}",
description="Error",
input_message_content=InputTextMessageContent(
html_parser.code(f"#{query}") + "That record was not found.",
" ".join([html_parser.code(f"#{query}"), "That record was not found."]),
parse_mode=ParseMode.HTML,
),
)