change: update config.ini
use definitions from danbooru dotenv, add comments Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
895f27470f
commit
496ea38b5c
4 changed files with 19 additions and 11 deletions
|
@ -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"{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).\n\n"
|
||||||
f"{html_parser.bold("currently configured instance:")}\n"
|
f"{html_parser.bold("currently configured instance:")}\n"
|
||||||
f"{html_parser.italic(config.get('Service', 'Name'))} ({config.get('Service', 'Domain')})",
|
f"{html_parser.italic(config.get('App', 'Name'))} ({config.get('App', 'Host')})",
|
||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
|
14
config.ini
14
config.ini
|
@ -1,8 +1,16 @@
|
||||||
[General]
|
[General]
|
||||||
|
; HTTP API token of Telegram bot.
|
||||||
|
; Can also be set with the BOT_TOKEN environment variable.
|
||||||
Token =
|
Token =
|
||||||
|
; (Optional) URL for "source code" button in /about.
|
||||||
|
; If not set, button will not appear in "about" menu.
|
||||||
SourceUrl =
|
SourceUrl =
|
||||||
|
|
||||||
[Service]
|
[App]
|
||||||
|
; Application name (e.g. Danbooru).
|
||||||
Name = Danbooru
|
Name = Danbooru
|
||||||
Domain = danbooru.donmai.us
|
; Host (without http://) used to access the application API.
|
||||||
PublicDomain = danbooru.donmai.us
|
Host = danbooru.donmai.us
|
||||||
|
; 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
|
|
@ -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('App', 'Host')}/posts/{query}.json")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
await invalid_query(update, query)
|
await invalid_query(update, query)
|
||||||
|
@ -40,8 +40,8 @@ async def answer_query(update: Update, query: str,
|
||||||
rating = format_rating(data['rating'])
|
rating = format_rating(data['rating'])
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(f"Open in {config.get('Service', 'Name')}",
|
InlineKeyboardButton(f"Open in {config.get('App', 'Name')}",
|
||||||
url=f"https://{config.get('Service', 'PublicDomain')}/posts/{query}"),
|
url=f"https://{config.get('App', 'HostName')}/posts/{query}"),
|
||||||
InlineKeyboardButton("View original", url=data['file_url'])
|
InlineKeyboardButton("View original", url=data['file_url'])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
8
main.py
8
main.py
|
@ -34,14 +34,14 @@ def main() -> None:
|
||||||
|
|
||||||
|
|
||||||
def validate_config() -> None:
|
def validate_config() -> None:
|
||||||
# TODO: do some PublicDomain checks or something
|
# TODO: do some HostName 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('App', 'Host')}/status.json")
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
print("Unable validate Domain in config.ini.")
|
print("Unable validate App.Host in config.ini.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ def get_token():
|
||||||
if config.get('General', 'Token') != "":
|
if config.get('General', 'Token') != "":
|
||||||
return config.get('General', 'Token')
|
return config.get('General', 'Token')
|
||||||
|
|
||||||
print("Set BOT_TOKEN environment variable or use config.ini to set bot token.")
|
print("Set BOT_TOKEN environment variable or use General.Token in config.ini to set bot token.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue