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(
|
await update.message.reply_text(
|
||||||
f"{html_parser.bold(f"about {context.bot.first_name}")}\n"
|
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"{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"(or other similar services).",
|
||||||
f"{html_parser.bold("currently configured instance:")}\n"
|
|
||||||
f"{html_parser.italic(config.get('Service', 'Name'))} ({config.get('Service', 'Domain')})",
|
|
||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,5 +4,4 @@ SourceUrl =
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Name = Danbooru
|
Name = Danbooru
|
||||||
Domain = danbooru.donmai.us
|
Host = danbooru.donmai.us
|
||||||
PublicDomain = danbooru.donmai.us
|
|
|
@ -21,7 +21,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
||||||
return
|
return
|
||||||
|
|
||||||
from main import config
|
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:
|
if response.status_code != 200:
|
||||||
await invalid_query(update, query)
|
await invalid_query(update, query)
|
||||||
|
@ -41,7 +41,7 @@ async def answer_query(update: Update, query: str,
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(f"Open in {config.get('Service', 'Name')}",
|
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'])
|
InlineKeyboardButton("View original", url=data['file_url'])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
3
main.py
3
main.py
|
@ -34,10 +34,9 @@ def main() -> None:
|
||||||
|
|
||||||
|
|
||||||
def validate_config() -> None:
|
def validate_config() -> None:
|
||||||
# TODO: do some PublicDomain checks or something
|
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
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:
|
if response.status_code != 200:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Add table
Reference in a new issue