feat: automatically get public domain from API
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
60e2b4e3af
commit
0927bb1185
4 changed files with 5 additions and 9 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -4,5 +4,4 @@ SourceUrl =
|
|||
|
||||
[Service]
|
||||
Name = Danbooru
|
||||
Domain = danbooru.donmai.us
|
||||
PublicDomain = danbooru.donmai.us
|
||||
Host = danbooru.donmai.us
|
|
@ -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'])
|
||||
]
|
||||
]
|
||||
|
|
3
main.py
3
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue