Compare commits
No commits in common. "b4e406d3515e76ed016cea04aee720310ddc9ca7" and "89f5b35395140acaba077a01a931b111272ab80d" have entirely different histories.
b4e406d351
...
89f5b35395
3 changed files with 20 additions and 41 deletions
58
commands.py
58
commands.py
|
@ -1,4 +1,4 @@
|
||||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, LinkPreviewOptions
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
from telegram.constants import ParseMode
|
from telegram.constants import ParseMode
|
||||||
from telegram.ext import ContextTypes
|
from telegram.ext import ContextTypes
|
||||||
|
|
||||||
|
@ -64,46 +64,26 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
||||||
uploader_data = get_json(f"users/{post_data['uploader_id']}")
|
uploader_data = get_json(f"users/{post_data['uploader_id']}")
|
||||||
# well, we could check the uploader, but why would we do that?
|
# well, we could check the uploader, but why would we do that?
|
||||||
|
|
||||||
keyboard = [
|
|
||||||
[
|
|
||||||
InlineKeyboardButton(f"Open in {app.name}",
|
|
||||||
url=f"https://{app.hostname}/posts/{post_id}")
|
|
||||||
]
|
|
||||||
]
|
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
||||||
|
|
||||||
# noinspection PyListCreation
|
|
||||||
m = []
|
|
||||||
m.append(f"ID: {html_parser.code(post_data['id'])}")
|
|
||||||
m.append(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']}")}")
|
|
||||||
m.append(f"Date: {post_data['created_at']}")
|
|
||||||
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"http://{app.host}/users/{post_data['approver_id']}")} "
|
|
||||||
f"{html_parser.hyperlink("»", f"http://{app.host}/posts?tags=approver:{approver_data['name']}")}")
|
|
||||||
m.append(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']}")}")
|
|
||||||
m.append(f"Source: {post_data['source'] if post_data['source'] != "" else "🚫"}")
|
|
||||||
m.append(f"Rating: {format_rating(post_data['rating'])}")
|
|
||||||
m.append(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']})")
|
|
||||||
m.append(f"Favorites: {html_parser.hyperlink(post_data['fav_count'],
|
|
||||||
f"http://{app.host}/posts/{post_data['id']}/favorites")}")
|
|
||||||
m.append(f"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(
|
await context.bot.edit_message_text(
|
||||||
f"{html_parser.bold("Information")}\n" + "\n".join(m),
|
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,
|
update.effective_chat.id, message.message_id,
|
||||||
parse_mode=ParseMode.HTML, reply_markup=reply_markup, link_preview_options=link_preview_options)
|
parse_mode=ParseMode.HTML)
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
f"{html_parser.bold("Usage")}: {html_parser.code(f"/info <post ID>")}",
|
f"{html_parser.bold("Usage")}: {html_parser.code(f"/info <post ID>")}",
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import Optional
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
_c = configparser.ConfigParser()
|
_c = configparser.ConfigParser()
|
||||||
_c.read("config.ini", "utf-8")
|
_c.read("config.ini")
|
||||||
|
|
||||||
|
|
||||||
class _General:
|
class _General:
|
||||||
|
|
|
@ -32,7 +32,6 @@ def format_rating(value: str) -> str | None:
|
||||||
case "e":
|
case "e":
|
||||||
# Negative Squared Latin Capital Letter E
|
# Negative Squared Latin Capital Letter E
|
||||||
return "🅴"
|
return "🅴"
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def format_status(data) -> str:
|
def format_status(data) -> str:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue