From a41417ee845bf8e0be33f94a3c1c74d8c9d55522 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Wed, 26 Mar 2025 14:03:28 +0300 Subject: [PATCH] feat: App.HostName is now optional Signed-off-by: mctaylors --- config.ini | 5 +++-- inline_query.py | 4 +++- main.py | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 08044d1..e06a7be 100644 --- a/config.ini +++ b/config.ini @@ -11,6 +11,7 @@ SourceUrl = Name = Danbooru ; Host (without http://) used to access the application API. Host = danbooru.donmai.us -; Public host name (without http://) for the “Open in [App.Name]” button. +; (Optional) Public host name (without http://) for the “Open in [App.Name]” button. ; Useful if the bot is hosted on the same server as the application. -HostName = danbooru.donmai.us \ No newline at end of file +; If not set, [App.Host] will be used instead. +HostName = \ No newline at end of file diff --git a/inline_query.py b/inline_query.py index 8aab066..c940ad7 100644 --- a/inline_query.py +++ b/inline_query.py @@ -38,10 +38,12 @@ 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']) + hostname = config.get('App', 'HostName') + hostname = hostname if hostname != "" else config.get('App', 'Host') keyboard = [ [ InlineKeyboardButton(f"Open in {config.get('App', 'Name')}", - url=f"https://{config.get('App', 'HostName')}/posts/{query}"), + url=f"https://{hostname}/posts/{query}"), InlineKeyboardButton("View original", url=data['file_url']) ] ] diff --git a/main.py b/main.py index e3f0baa..9d7f581 100644 --- a/main.py +++ b/main.py @@ -34,7 +34,6 @@ def main() -> None: def validate_config() -> None: - # TODO: do some HostName checks or something # noinspection PyBroadException try: response = requests.get(f"http://{config.get('App', 'Host')}/status.json")