feat: use status.json for "Open in" button

oh yeah and we're also going to make breaking changes to config because we can

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2025-03-25 22:00:50 +03:00
parent e5277d50f8
commit 4a2a2e9920
Signed by: mctaylors
GPG key ID: 4EEF4F949A266EE2
3 changed files with 5 additions and 5 deletions

View file

@ -4,5 +4,4 @@ SourceUrl =
[Service]
Name = Danbooru
Domain = danbooru.donmai.us
PublicDomain = danbooru.donmai.us
Host = danbooru.donmai.us

View file

@ -21,7 +21,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
return
from main import config
response = requests.get(f"http://{config.get('Service', 'Domain')}/posts/{query}.json")
response = requests.get(f"http://{config.get('Service', 'Host')}/posts/{query}.json")
if response.status_code != 200:
await invalid_query(update, query)
@ -38,10 +38,11 @@ async def answer_query(update: Update, query: str,
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'])
status_json = requests.get(f"http://{config.get('Service', 'Host')}/status.json").json()
keyboard = [
[
InlineKeyboardButton(f"Open in {config.get('Service', 'Name')}",
url=f"https://{config.get('Service', 'PublicDomain')}/posts/{query}"),
url=f"https://{status_json['headers']['Host']}/posts/{query}"),
InlineKeyboardButton("View original", url=data['file_url'])
]
]

View file

@ -37,7 +37,7 @@ def validate_config() -> None:
# TODO: do some PublicDomain checks or something
# noinspection PyBroadException
try:
response = requests.get(f"http://{config.get('Service', 'Domain')}/profile.json")
response = requests.get(f"http://{config.get('Service', 'Host')}/status.json")
if response.status_code != 200:
raise
except: