feat: add /info command, pt. 1
This commit is contained in:
parent
93e3ca4f96
commit
89f5b35395
4 changed files with 79 additions and 6 deletions
43
commands.py
43
commands.py
|
@ -4,6 +4,7 @@ from telegram.ext import ContextTypes
|
|||
|
||||
import html_parser
|
||||
from config import *
|
||||
from extensions import get_json, format_rating, format_status
|
||||
|
||||
|
||||
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
|
@ -45,3 +46,45 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
|
|||
parse_mode=ParseMode.HTML,
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
|
||||
async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
try:
|
||||
post_id = context.args[0]
|
||||
message = await context.bot.send_message(update.effective_chat.id,
|
||||
f"{html_parser.bold("Information")}\n"
|
||||
f"Fetching...",
|
||||
parse_mode=ParseMode.HTML)
|
||||
post_data = get_json(f"posts/{post_id}")
|
||||
if post_data is None:
|
||||
await update.message.reply_text(
|
||||
f"{html_parser.bold("Error")}: That record was not found.",
|
||||
parse_mode=ParseMode.HTML)
|
||||
return
|
||||
uploader_data = get_json(f"users/{post_data['uploader_id']}")
|
||||
# well, we could check the uploader, but why would we do that?
|
||||
|
||||
await context.bot.edit_message_text(
|
||||
f"{html_parser.bold("Information")}\n"
|
||||
f"ID: {html_parser.code(post_data['id'])}\n"
|
||||
f"Uploader: {html_parser.hyperlink(uploader_data['name'],
|
||||
f"http://{app.host}/users/{post_data['uploader_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.host}/posts?tags=user:{uploader_data['name']}")}\n"
|
||||
f"Date: {post_data['created_at']}\n"
|
||||
f"Size: {post_data['media_asset']['file_size']} .{post_data['media_asset']['file_ext']} "
|
||||
f"({post_data['media_asset']['image_width']}x{post_data['media_asset']['image_height']}) "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.host}/media_assets/{post_data['media_asset']['id']}")}\n"
|
||||
f"Source: {post_data['source']}\n"
|
||||
f"Rating: {format_rating(post_data['rating'])}\n"
|
||||
f"Score: {html_parser.hyperlink(post_data['score'],
|
||||
f"http://{app.host}/post_votes?search[post_id]={post_data['id']}&variant=compact")} "
|
||||
f"(+{post_data['up_score']} / -{post_data['down_score']})\n"
|
||||
f"Favorites: {html_parser.hyperlink(post_data['fav_count'],
|
||||
f"http://{app.host}/posts/{post_data['id']}/favorites")}\n"
|
||||
f"Status: {format_status(post_data)}",
|
||||
update.effective_chat.id, message.message_id,
|
||||
parse_mode=ParseMode.HTML)
|
||||
except (IndexError, ValueError):
|
||||
await update.message.reply_text(
|
||||
f"{html_parser.bold("Usage")}: {html_parser.code(f"/info <post ID>")}",
|
||||
parse_mode=ParseMode.HTML)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue