From 4a2a2e99201ae8c03788dd99c38c59b20971a0e3 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Tue, 25 Mar 2025 22:00:50 +0300 Subject: [PATCH] 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 --- config.ini | 3 +-- inline_query.py | 5 +++-- main.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config.ini b/config.ini index cfde3e4..9596553 100644 --- a/config.ini +++ b/config.ini @@ -4,5 +4,4 @@ SourceUrl = [Service] Name = Danbooru -Domain = danbooru.donmai.us -PublicDomain = danbooru.donmai.us \ No newline at end of file +Host = danbooru.donmai.us \ No newline at end of file diff --git a/inline_query.py b/inline_query.py index 65b1cfb..7fa3c8f 100644 --- a/inline_query.py +++ b/inline_query.py @@ -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']) ] ] diff --git a/main.py b/main.py index 7329782..a3e5b2d 100644 --- a/main.py +++ b/main.py @@ -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: