style: some weird black code reformatting
This commit is contained in:
parent
673a3768b8
commit
9ad1ce38ee
5 changed files with 82 additions and 53 deletions
97
commands.py
97
commands.py
|
@ -1,4 +1,9 @@
|
|||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, LinkPreviewOptions
|
||||
from telegram import (
|
||||
Update,
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
LinkPreviewOptions,
|
||||
)
|
||||
from telegram.constants import ParseMode
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
|
@ -12,7 +17,7 @@ async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
|
|||
await update.message.reply_text(
|
||||
f"hello, i'm {html_parser.bold(context.bot.first_name)}, an inline image grabber.\n\n"
|
||||
f"to get help, use /help",
|
||||
parse_mode=ParseMode.HTML
|
||||
parse_mode=ParseMode.HTML,
|
||||
)
|
||||
|
||||
|
||||
|
@ -24,18 +29,14 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
f"2. click on the box that has popped up\n"
|
||||
f"3. ???\n"
|
||||
f"4. done!",
|
||||
parse_mode=ParseMode.HTML
|
||||
parse_mode=ParseMode.HTML,
|
||||
)
|
||||
|
||||
|
||||
async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
reply_markup = None
|
||||
if general.sourceurl is not None:
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"source code", url=general.sourceurl)
|
||||
]
|
||||
]
|
||||
keyboard = [[InlineKeyboardButton(f"source code", url=general.sourceurl)]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
await update.message.reply_text(
|
||||
|
@ -45,30 +46,33 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
|
|||
f"{html_parser.bold("currently configured instance:")}\n"
|
||||
f"{html_parser.italic(app.name)} ({app.hostname})",
|
||||
parse_mode=ParseMode.HTML,
|
||||
reply_markup=reply_markup
|
||||
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)
|
||||
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)
|
||||
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?
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"Open in {app.name}",
|
||||
url=f"http://{app.hostname}/posts/{post_id}")
|
||||
InlineKeyboardButton(
|
||||
f"Open in {app.name}", url=f"http://{app.hostname}/posts/{post_id}"
|
||||
)
|
||||
]
|
||||
]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
@ -76,41 +80,60 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
# noinspection PyListCreation
|
||||
m = []
|
||||
m.append(f"ID: {html_parser.code(post_data['id'])}")
|
||||
m.append(f"Uploader: {html_parser.hyperlink(uploader_data['name'],
|
||||
m.append(
|
||||
f"Uploader: {html_parser.hyperlink(uploader_data['name'],
|
||||
f"http://{app.hostname}/users/{post_data['uploader_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.hostname}/posts?tags=user:{uploader_data['name']}")}")
|
||||
created_at = datetime.fromisoformat(post_data['created_at'])
|
||||
m.append(f"Date: {html_parser.hyperlink(
|
||||
f"{html_parser.hyperlink("»", f"http://{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"http://{app.hostname}/posts?tags=date:{created_at.strftime("%Y-%m-%d")}")}")
|
||||
if post_data['approver_id'] is not None:
|
||||
f"http://{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'],
|
||||
m.append(
|
||||
f"Approver: {html_parser.hyperlink(approver_data['name'],
|
||||
f"http://{app.hostname}/users/{post_data['approver_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.hostname}/posts?tags=approver:{approver_data['name']}")}")
|
||||
m.append(f"Size: {html_parser.hyperlink(
|
||||
f"{html_parser.hyperlink("»", f"http://{app.hostname}/posts?tags=approver:{approver_data['name']}")}"
|
||||
)
|
||||
m.append(
|
||||
f"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"http://{app.hostname}/media_assets/{post_data['media_asset']['id']}")}")
|
||||
m.append(f"Source: {post_data['source'] if post_data['source'] != "" else "🚫"}")
|
||||
f"({post_data['media_asset']['image_width']}x{post_data['media_asset']['image_height']}) "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.hostname}/media_assets/{post_data['media_asset']['id']}")}"
|
||||
)
|
||||
m.append(
|
||||
f"Source: {post_data['source'] if post_data['source'] is not "" else "🚫"}"
|
||||
)
|
||||
m.append(f"Rating: {format_rating(post_data['rating'])}")
|
||||
m.append(f"Score: {html_parser.hyperlink(post_data['score'],
|
||||
m.append(
|
||||
f"Score: {html_parser.hyperlink(post_data['score'],
|
||||
f"http://{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"http://{app.hostname}/posts/{post_data['id']}/favorites")}")
|
||||
f"(+{post_data['up_score']} / -{post_data['down_score']})"
|
||||
)
|
||||
m.append(
|
||||
f"Favorites: {html_parser.hyperlink(post_data['fav_count'],
|
||||
f"http://{app.hostname}/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'])
|
||||
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),
|
||||
update.effective_chat.id, message.message_id,
|
||||
parse_mode=ParseMode.HTML, reply_markup=reply_markup, link_preview_options=link_preview_options)
|
||||
update.effective_chat.id,
|
||||
message.message_id,
|
||||
parse_mode=ParseMode.HTML,
|
||||
reply_markup=reply_markup,
|
||||
link_preview_options=link_preview_options,
|
||||
)
|
||||
except (IndexError, ValueError):
|
||||
await update.message.reply_text(
|
||||
f"{html_parser.bold("Usage")}: {html_parser.code(f"/info <post ID>")}",
|
||||
parse_mode=ParseMode.HTML)
|
||||
parse_mode=ParseMode.HTML,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue