refactor: pt. 1: use joins in info_command
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
fff77f51f8
commit
6ea4f2c3ed
1 changed files with 78 additions and 25 deletions
101
commands.py
101
commands.py
|
@ -81,52 +81,103 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
m = [
|
||||
f"ID: {html_parser.code(post_data['id'])}",
|
||||
f"Uploader: {html_parser.hyperlink(uploader_data['name'],
|
||||
f"{app.protocol}://{app.hostname}/users/{post_data['uploader_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"{app.protocol}://{app.hostname}/posts?tags=user:{uploader_data['name']}")}",
|
||||
" ".join(["ID:", html_parser.code(post_data["id"])]),
|
||||
" ".join(
|
||||
[
|
||||
"Uploader:",
|
||||
html_parser.hyperlink(
|
||||
uploader_data["name"],
|
||||
f"{app.protocol}://{app.hostname}/users/{post_data['uploader_id']}",
|
||||
),
|
||||
html_parser.hyperlink(
|
||||
"»",
|
||||
f"{app.protocol}://{app.hostname}/posts?tags=user:{uploader_data['name']}",
|
||||
),
|
||||
]
|
||||
),
|
||||
]
|
||||
created_at = datetime.fromisoformat(post_data["created_at"])
|
||||
m.append(
|
||||
f"Date: {html_parser.hyperlink(
|
||||
f"{created_at.strftime("%Y-%m-%d %X (%z)")}",
|
||||
f"{app.protocol}://{app.hostname}/posts?tags=date:{created_at.strftime("%Y-%m-%d")}")}"
|
||||
" ".join(
|
||||
[
|
||||
"Date:",
|
||||
html_parser.hyperlink(
|
||||
created_at.strftime("%Y-%m-%d %X (%z)"),
|
||||
f"{app.protocol}://{app.hostname}/posts?tags=date:{created_at.strftime("%Y-%m-%d")}",
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
if post_data["approver_id"] is not None:
|
||||
approver_data = get_json(f"users/{post_data['approver_id']}")
|
||||
m.append(
|
||||
f"Approver: {html_parser.hyperlink(approver_data['name'],
|
||||
f"{app.protocol}://{app.hostname}/users/{post_data['approver_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"{app.protocol}://{app.hostname}/posts?tags=approver:{approver_data['name']}")}"
|
||||
" ".join(
|
||||
[
|
||||
"Approver:",
|
||||
html_parser.hyperlink(
|
||||
approver_data["name"],
|
||||
f"{app.protocol}://{app.hostname}/users/{post_data['approver_id']}",
|
||||
),
|
||||
html_parser.hyperlink(
|
||||
"»",
|
||||
f"{app.protocol}://{app.hostname}/posts?tags=approver:{approver_data['name']}",
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
m.append(
|
||||
f"Size: {html_parser.hyperlink(
|
||||
" ".join(
|
||||
[
|
||||
"Size:",
|
||||
html_parser.hyperlink(
|
||||
f"{humanize_filesize(post_data['media_asset']['file_size'])} .{post_data['media_asset']['file_ext']}",
|
||||
"" if post_data['is_banned'] else post_data['file_url'])} "
|
||||
f"({post_data['media_asset']['image_width']}x{post_data['media_asset']['image_height']}) "
|
||||
f"{html_parser.hyperlink("»", f"{app.protocol}://{app.hostname}/media_assets/{post_data['media_asset']['id']}")}"
|
||||
"" if post_data["is_banned"] else post_data["file_url"],
|
||||
),
|
||||
f"({post_data['media_asset']['image_width']}x{post_data['media_asset']['image_height']})",
|
||||
html_parser.hyperlink(
|
||||
"»",
|
||||
f"{app.protocol}://{app.hostname}/media_assets/{post_data['media_asset']['id']}",
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
m.append(
|
||||
f"Source: {post_data['source'] if post_data['source'] != "" else "🚫"}"
|
||||
" ".join(
|
||||
["Source:", post_data["source"] if post_data["source"] != "" else "🚫"]
|
||||
)
|
||||
m.append(f"Rating: {format_rating(post_data['rating'])}")
|
||||
)
|
||||
m.append(" ".join(["Rating:", format_rating(post_data["rating"])]))
|
||||
m.append(
|
||||
f"Score: {html_parser.hyperlink(post_data['score'],
|
||||
f"{app.protocol}://{app.hostname}/post_votes?search[post_id]={post_data['id']}&variant=compact")} "
|
||||
f"(+{post_data['up_score']} / -{post_data['down_score']})"
|
||||
" ".join(
|
||||
[
|
||||
"Score:",
|
||||
html_parser.hyperlink(
|
||||
post_data["score"],
|
||||
f"{app.protocol}://{app.hostname}/post_votes?search[post_id]={post_data['id']}&variant=compact",
|
||||
),
|
||||
f"(+{post_data['up_score']} / -{post_data['down_score']})",
|
||||
]
|
||||
)
|
||||
)
|
||||
m.append(
|
||||
f"Favorites: {html_parser.hyperlink(post_data['fav_count'],
|
||||
f"{app.protocol}://{app.hostname}/posts/{post_data['id']}/favorites")}"
|
||||
" ".join(
|
||||
[
|
||||
"Favorites:",
|
||||
html_parser.hyperlink(
|
||||
post_data["fav_count"],
|
||||
f"{app.protocol}://{app.hostname}/posts/{post_data['id']}/favorites",
|
||||
),
|
||||
]
|
||||
)
|
||||
m.append(f"Status: {format_status(post_data)}")
|
||||
)
|
||||
m.append(" ".join(["Status:", format_status(post_data)]))
|
||||
|
||||
link_preview_options = LinkPreviewOptions(True)
|
||||
if not post_data["is_banned"]:
|
||||
link_preview_options = LinkPreviewOptions(url=post_data["large_file_url"])
|
||||
|
||||
await context.bot.edit_message_text(
|
||||
f"{html_parser.bold("Information")}\n" + "\n".join(m),
|
||||
"\n".join([html_parser.bold("Information")] + m),
|
||||
update.effective_chat.id,
|
||||
message.message_id,
|
||||
parse_mode=ParseMode.HTML,
|
||||
|
@ -135,6 +186,8 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
)
|
||||
except (IndexError, ValueError):
|
||||
await update.message.reply_text(
|
||||
f"{html_parser.bold("Usage")}: {html_parser.code(f"/info <post ID>")}",
|
||||
" ".join(
|
||||
[html_parser.bold("Usage:"), html_parser.code("/info <post ID>")]
|
||||
),
|
||||
parse_mode=ParseMode.HTML,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue