Compare commits
No commits in common. "93e3ca4f96740466842be8a66aa880b7603297a0" and "5262975275bfa7247a2da66b6b335e5615ba6b84" have entirely different histories.
93e3ca4f96
...
5262975275
4 changed files with 6 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
|
||||
def humanize_tags_from_json(value: str, default: str) -> str:
|
||||
def humanize_tags_from_json(value: str, default: str):
|
||||
if value != "":
|
||||
output = str()
|
||||
tags = value.split()
|
||||
|
@ -14,7 +14,7 @@ def humanize_tags_from_json(value: str, default: str) -> str:
|
|||
return default
|
||||
|
||||
|
||||
def format_rating(value: str) -> str | None:
|
||||
def format_rating(value: str):
|
||||
match value:
|
||||
case "g":
|
||||
# Negative Squared Latin Capital Letter G
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from uuid import uuid4
|
||||
|
||||
import requests
|
||||
from telegram import Update, InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent, \
|
||||
InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
|
@ -35,25 +36,6 @@ 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}",
|
||||
|
@ -86,10 +68,9 @@ async def invalid_query(update: Update, query: str) -> None:
|
|||
InlineQueryResultArticle(
|
||||
id=str(uuid4()),
|
||||
title=f"ID: {query}",
|
||||
description="Error",
|
||||
description="not found.",
|
||||
input_message_content=InputTextMessageContent(
|
||||
f"ID: <code>{query}</code>\n"
|
||||
f"That record was not found.",
|
||||
f"ID: <code>{query}</code>\n<b>requested post does not exist.</b>",
|
||||
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() -> None:
|
||||
def get_token():
|
||||
if os.getenv("BOT_TOKEN") is not None:
|
||||
return os.getenv("BOT_TOKEN")
|
||||
|
||||
|
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue