From 0927bb1185936803d5c134d50add99e69d36a5a5 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Tue, 25 Mar 2025 22:59:15 +0300 Subject: [PATCH] feat: automatically get public domain from API Signed-off-by: mctaylors --- commands.py | 4 +--- config.ini | 3 +-- inline_query.py | 4 ++-- main.py | 3 +-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/commands.py b/commands.py index c2119db..e8a0759 100644 --- a/commands.py +++ b/commands.py @@ -40,9 +40,7 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N await update.message.reply_text( f"{html_parser.bold(f"about {context.bot.first_name}")}\n" f"{context.bot.first_name} is an inline image grabber written in python that grabs images from Danbooru " - f"(or other similar services).\n\n" - f"{html_parser.bold("currently configured instance:")}\n" - f"{html_parser.italic(config.get('Service', 'Name'))} ({config.get('Service', 'Domain')})", + f"(or other similar services).", parse_mode=ParseMode.HTML, reply_markup=reply_markup ) 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..6617ba8 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) @@ -41,7 +41,7 @@ async def answer_query(update: Update, query: str, keyboard = [ [ InlineKeyboardButton(f"Open in {config.get('Service', 'Name')}", - url=f"https://{config.get('Service', 'PublicDomain')}/posts/{query}"), + url=f"{data['file_url'].partition('/data/')[0]}/posts/{query}"), InlineKeyboardButton("View original", url=data['file_url']) ] ] diff --git a/main.py b/main.py index caa22e1..133535d 100644 --- a/main.py +++ b/main.py @@ -34,10 +34,9 @@ def main() -> None: def validate_config() -> None: - # TODO: do some PublicDomain checks or something # noinspection PyBroadException try: - response = requests.get(f"http://{config.get('Service', 'Domain')}/status.json") + response = requests.get(f"http://{config.get('Service', 'Host')}/status.json") if response.status_code != 200: raise except: