Compare commits

..

No commits in common. "a41417ee845bf8e0be33f94a3c1c74d8c9d55522" and "895f27470f4a4294e785a6cbd14ae5deaa7e7719" have entirely different histories.

4 changed files with 11 additions and 21 deletions

View file

@ -42,7 +42,7 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> 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('App', 'Name'))} ({config.get('App', 'Host')})",
f"{html_parser.italic(config.get('Service', 'Name'))} ({config.get('Service', 'Domain')})",
parse_mode=ParseMode.HTML,
reply_markup=reply_markup
)

View file

@ -1,17 +1,8 @@
[General]
; HTTP API token of Telegram bot.
; Can also be set with the BOT_TOKEN environment variable.
Token =
; (Optional) URL for "source code" button in /about.
; If not set, button will not appear in "about" menu.
SourceUrl =
[App]
; Application name (e.g. Danbooru).
[Service]
Name = Danbooru
; Host (without http://) used to access the application API.
Host = danbooru.donmai.us
; (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.
; If not set, [App.Host] will be used instead.
HostName =
Domain = danbooru.donmai.us
PublicDomain = danbooru.donmai.us

View file

@ -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('App', 'Host')}/posts/{query}.json")
response = requests.get(f"http://{config.get('Service', 'Domain')}/posts/{query}.json")
if response.status_code != 200:
await invalid_query(update, query)
@ -38,12 +38,10 @@ 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://{hostname}/posts/{query}"),
InlineKeyboardButton(f"Open in {config.get('Service', 'Name')}",
url=f"https://{config.get('Service', 'PublicDomain')}/posts/{query}"),
InlineKeyboardButton("View original", url=data['file_url'])
]
]

View file

@ -34,13 +34,14 @@ def main() -> None:
def validate_config() -> None:
# TODO: do some PublicDomain checks or something
# noinspection PyBroadException
try:
response = requests.get(f"http://{config.get('App', 'Host')}/status.json")
response = requests.get(f"http://{config.get('Service', 'Domain')}/status.json")
if response.status_code != 200:
raise
except:
print("Unable validate App.Host in config.ini.")
print("Unable validate Domain in config.ini.")
exit(1)
@ -51,7 +52,7 @@ def get_token():
if config.get('General', 'Token') != "":
return config.get('General', 'Token')
print("Set BOT_TOKEN environment variable or use General.Token in config.ini to set bot token.")
print("Set BOT_TOKEN environment variable or use config.ini to set bot token.")
exit(1)