feat: add "Show information" button
All checks were successful
Build / Upload to production (push) Successful in 1m43s

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2025-06-08 23:44:55 +03:00
parent 86e9c04e1e
commit c1f803503e
Signed by: mctaylors
GPG key ID: 4EEF4F949A266EE2
2 changed files with 19 additions and 12 deletions

View file

@ -7,12 +7,12 @@ from telegram import (
InputTextMessageContent, InputTextMessageContent,
InlineKeyboardMarkup, InlineKeyboardMarkup,
LinkPreviewOptions, LinkPreviewOptions,
helpers,
) )
from telegram.constants import ParseMode from telegram.constants import ParseMode
from telegram.ext import ContextTypes from telegram.ext import ContextTypes
import html_parser import html_parser
from config import *
from extensions import humanize_tags_from_json, format_rating, get_json from extensions import humanize_tags_from_json, format_rating, get_json
@ -34,10 +34,12 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
await invalid_query(update, query) await invalid_query(update, query)
return return
await answer_query(update, query, data) await answer_query(update, context, query, data)
async def answer_query(update: Update, query: int, data) -> None: async def answer_query(
update: Update, context: ContextTypes.DEFAULT_TYPE, query: int, data
) -> None:
characters = humanize_tags_from_json(data["tag_string_character"], "no characters") characters = humanize_tags_from_json(data["tag_string_character"], "no characters")
copyrights = humanize_tags_from_json( copyrights = humanize_tags_from_json(
data["tag_string_copyright"], "unknown copyright" data["tag_string_copyright"], "unknown copyright"
@ -45,6 +47,15 @@ async def answer_query(update: Update, query: int, data) -> None:
artists = humanize_tags_from_json(data["tag_string_artist"], "unknown artist") artists = humanize_tags_from_json(data["tag_string_artist"], "unknown artist")
rating = format_rating(data["rating"]) rating = format_rating(data["rating"])
keyboard = [
[
InlineKeyboardButton(
"Show information",
url=helpers.create_deep_linked_url(context.bot.username, str(query)),
),
]
]
if data["is_banned"]: if data["is_banned"]:
results = [ results = [
InlineQueryResultArticle( InlineQueryResultArticle(
@ -72,21 +83,14 @@ async def answer_query(update: Update, query: int, data) -> None:
), ),
parse_mode=ParseMode.HTML, parse_mode=ParseMode.HTML,
), ),
reply_markup=InlineKeyboardMarkup(keyboard),
) )
] ]
await update.inline_query.answer(results) await update.inline_query.answer(results)
return return
keyboard = [ keyboard[0].append(InlineKeyboardButton("View original", url=data["file_url"]))
[
InlineKeyboardButton(
f"Open in {app.name}",
url=f"{app.protocol}://{app.hostname}/posts/{query}",
),
InlineKeyboardButton("View original", url=data["file_url"]),
]
]
results = [ results = [
InlineQueryResultArticle( InlineQueryResultArticle(

View file

@ -19,6 +19,9 @@ def main() -> None:
import commands import commands
application.add_handler(
CommandHandler("start", commands.info_command, has_args=True)
)
application.add_handler(CommandHandler("start", commands.start_command)) application.add_handler(CommandHandler("start", commands.start_command))
application.add_handler(CommandHandler("help", commands.help_command)) application.add_handler(CommandHandler("help", commands.help_command))
application.add_handler(CommandHandler("about", commands.about_command)) application.add_handler(CommandHandler("about", commands.about_command))