Compare commits
5 commits
5262975275
...
93e3ca4f96
Author | SHA1 | Date | |
---|---|---|---|
93e3ca4f96 | |||
bd39df5368 | |||
8909210e2e | |||
3518f4bbf0 | |||
58d7050dc3 |
4 changed files with 25 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
|
||||
def humanize_tags_from_json(value: str, default: str):
|
||||
def humanize_tags_from_json(value: str, default: str) -> str:
|
||||
if value != "":
|
||||
output = str()
|
||||
tags = value.split()
|
||||
|
@ -14,7 +14,7 @@ def humanize_tags_from_json(value: str, default: str):
|
|||
return default
|
||||
|
||||
|
||||
def format_rating(value: str):
|
||||
def format_rating(value: str) -> str | None:
|
||||
match value:
|
||||
case "g":
|
||||
# Negative Squared Latin Capital Letter G
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from uuid import uuid4
|
||||
|
||||
import requests
|
||||
from telegram import Update, InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent, \
|
||||
InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
|
@ -36,6 +35,25 @@ async def answer_query(update: Update, query: str, data) -> None:
|
|||
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']:
|
||||
results = [
|
||||
InlineQueryResultArticle(
|
||||
id=str(uuid4()),
|
||||
title=f"ID: {query}",
|
||||
description=f"{characters} ({copyrights}) drawn by {artists}",
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"ID: <code>{query}</code> {rating}\n"
|
||||
f"<s><b>{characters} ({copyrights})</b> drawn by <b>{artists}</b></s>\n"
|
||||
f"This post has been removed because of a takedown request or rule violation.",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
await update.inline_query.answer(results)
|
||||
return
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"Open in {app.name}",
|
||||
|
@ -68,9 +86,10 @@ async def invalid_query(update: Update, query: str) -> None:
|
|||
InlineQueryResultArticle(
|
||||
id=str(uuid4()),
|
||||
title=f"ID: {query}",
|
||||
description="not found.",
|
||||
description="Error",
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"ID: <code>{query}</code>\n<b>requested post does not exist.</b>",
|
||||
f"ID: <code>{query}</code>\n"
|
||||
f"That record was not found.",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
)
|
||||
|
|
2
main.py
2
main.py
|
@ -28,7 +28,7 @@ def main() -> None:
|
|||
application.run_polling(allowed_updates=commands.Update.ALL_TYPES)
|
||||
|
||||
|
||||
def get_token():
|
||||
def get_token() -> None:
|
||||
if os.getenv("BOT_TOKEN") is not None:
|
||||
return os.getenv("BOT_TOKEN")
|
||||
|
||||
|
|
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue