feat: add "Show information" button
All checks were successful
Build / Upload to production (push) Successful in 1m43s
All checks were successful
Build / Upload to production (push) Successful in 1m43s
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
86e9c04e1e
commit
c1f803503e
2 changed files with 19 additions and 12 deletions
|
@ -7,12 +7,12 @@ from telegram import (
|
|||
InputTextMessageContent,
|
||||
InlineKeyboardMarkup,
|
||||
LinkPreviewOptions,
|
||||
helpers,
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
|
@ -34,10 +34,12 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
await invalid_query(update, query)
|
||||
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")
|
||||
copyrights = humanize_tags_from_json(
|
||||
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")
|
||||
rating = format_rating(data["rating"])
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Show information",
|
||||
url=helpers.create_deep_linked_url(context.bot.username, str(query)),
|
||||
),
|
||||
]
|
||||
]
|
||||
|
||||
if data["is_banned"]:
|
||||
results = [
|
||||
InlineQueryResultArticle(
|
||||
|
@ -72,21 +83,14 @@ async def answer_query(update: Update, query: int, data) -> None:
|
|||
),
|
||||
parse_mode=ParseMode.HTML,
|
||||
),
|
||||
reply_markup=InlineKeyboardMarkup(keyboard),
|
||||
)
|
||||
]
|
||||
|
||||
await update.inline_query.answer(results)
|
||||
return
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
f"Open in {app.name}",
|
||||
url=f"{app.protocol}://{app.hostname}/posts/{query}",
|
||||
),
|
||||
InlineKeyboardButton("View original", url=data["file_url"]),
|
||||
]
|
||||
]
|
||||
keyboard[0].append(InlineKeyboardButton("View original", url=data["file_url"]))
|
||||
|
||||
results = [
|
||||
InlineQueryResultArticle(
|
||||
|
|
3
main.py
3
main.py
|
@ -19,6 +19,9 @@ def main() -> None:
|
|||
|
||||
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("help", commands.help_command))
|
||||
application.add_handler(CommandHandler("about", commands.about_command))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue