Compare commits
2 commits
10c2d58efb
...
78db4c85db
Author | SHA1 | Date | |
---|---|---|---|
78db4c85db | |||
bd957e2bd2 |
2 changed files with 46 additions and 31 deletions
18
commands.py
18
commands.py
|
@ -68,7 +68,7 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"Open in {app.name}",
|
||||
url=f"https://{app.hostname}/posts/{post_id}")
|
||||
url=f"http://{app.hostname}/posts/{post_id}")
|
||||
]
|
||||
]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
@ -77,29 +77,29 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
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']}")}")
|
||||
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"{created_at.strftime("%Y-%m-%d %X (%z)")}",
|
||||
f"http://{app.host}/posts?tags=date:{created_at.strftime("%Y-%m-%d")}")}")
|
||||
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'],
|
||||
f"http://{app.host}/users/{post_data['approver_id']}")} "
|
||||
f"{html_parser.hyperlink("»", f"http://{app.host}/posts?tags=approver:{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"{humanize_filesize(post_data['media_asset']['file_size'])} .{post_data['media_asset']['file_ext']}",
|
||||
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.host}/media_assets/{post_data['media_asset']['id']}")}")
|
||||
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 "🚫"}")
|
||||
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"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.host}/posts/{post_data['id']}/favorites")}")
|
||||
f"http://{app.hostname}/posts/{post_data['id']}/favorites")}")
|
||||
m.append(f"Status: {format_status(post_data)}")
|
||||
|
||||
link_preview_options = LinkPreviewOptions(True)
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
from uuid import uuid4
|
||||
|
||||
from telegram import Update, InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent, \
|
||||
InlineKeyboardMarkup, LinkPreviewOptions
|
||||
from telegram import (
|
||||
Update,
|
||||
InlineKeyboardButton,
|
||||
InlineQueryResultArticle,
|
||||
InputTextMessageContent,
|
||||
InlineKeyboardMarkup,
|
||||
LinkPreviewOptions,
|
||||
)
|
||||
from telegram.constants import ParseMode
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
import html_parser
|
||||
from config import *
|
||||
from extensions import humanize_tags_from_json, format_rating, get_json
|
||||
|
||||
|
@ -28,22 +35,29 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
|
||||
|
||||
async def answer_query(update: Update, query: str, data) -> None:
|
||||
characters = humanize_tags_from_json(data['tag_string_character'], "no characters")
|
||||
copyrights = humanize_tags_from_json(data['tag_string_copyright'], "unknown copyright")
|
||||
artists = humanize_tags_from_json(data['tag_string_artist'], "unknown artist")
|
||||
rating = format_rating(data['rating'])
|
||||
characters = humanize_tags_from_json(data["tag_string_character"], "no characters")
|
||||
copyrights = humanize_tags_from_json(
|
||||
data["tag_string_copyright"], "unknown copyright"
|
||||
)
|
||||
artists = humanize_tags_from_json(data["tag_string_artist"], "unknown artist")
|
||||
rating = format_rating(data["rating"])
|
||||
|
||||
if data['is_banned']:
|
||||
if data["is_banned"]:
|
||||
results = [
|
||||
InlineQueryResultArticle(
|
||||
id=str(uuid4()),
|
||||
title=f"ID: {query}",
|
||||
description=f"{characters} ({copyrights}) drawn by {artists}",
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"<code>#{query}</code> <s><b>{characters} ({copyrights})</b> drawn by <b>{artists}</b></s> {rating}\n"
|
||||
f"This post has been removed because of a takedown request or rule violation.",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
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.",
|
||||
parse_mode=ParseMode.HTML,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -52,9 +66,10 @@ async def answer_query(update: Update, query: str, data) -> None:
|
|||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"Open in {app.name}",
|
||||
url=f"https://{app.hostname}/posts/{query}"),
|
||||
InlineKeyboardButton("View original", url=data['file_url'])
|
||||
InlineKeyboardButton(
|
||||
f"Open in {app.name}", url=f"http://{app.hostname}/posts/{query}"
|
||||
),
|
||||
InlineKeyboardButton("View original", url=data["file_url"]),
|
||||
]
|
||||
]
|
||||
|
||||
|
@ -63,13 +78,14 @@ async def answer_query(update: Update, query: str, data) -> None:
|
|||
id=str(uuid4()),
|
||||
title=f"ID: {query}",
|
||||
description=f"{characters} ({copyrights}) drawn by {artists}",
|
||||
thumbnail_url=data['preview_file_url'],
|
||||
thumbnail_url=data["preview_file_url"],
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"<code>#{query}</code> <b>{characters} ({copyrights})</b> drawn by <b>{artists}</b> {rating}",
|
||||
html_parser.code(f"#{query}")
|
||||
+ f" {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'])
|
||||
link_preview_options=LinkPreviewOptions(url=data["large_file_url"]),
|
||||
),
|
||||
reply_markup=InlineKeyboardMarkup(keyboard)
|
||||
reply_markup=InlineKeyboardMarkup(keyboard),
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -83,10 +99,9 @@ async def invalid_query(update: Update, query: str) -> None:
|
|||
title=f"ID: {query}",
|
||||
description="Error",
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"<code>#{query}</code>\n"
|
||||
f"That record was not found.",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
html_parser.code(f"#{query}") + "That record was not found.",
|
||||
parse_mode=ParseMode.HTML,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue