refactor: add config.py
this change adds self validation in __init__, allows to make config values with different types (not just string) and stores config values in classes for easier accessibility Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
768f9abdcf
commit
5262975275
5 changed files with 57 additions and 35 deletions
|
@ -6,9 +6,8 @@ from telegram import Update, InlineKeyboardButton, InlineQueryResultArticle, Inp
|
|||
from telegram.constants import ParseMode
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
import main
|
||||
from config import *
|
||||
from extensions import humanize_tags_from_json, format_rating
|
||||
from main import config
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
|
@ -21,7 +20,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
if not query.isdigit():
|
||||
return
|
||||
|
||||
response = requests.get(f"http://{config.get('App', 'Host')}/posts/{query}.json")
|
||||
response = requests.get(f"http://{app.host}/posts/{query}.json")
|
||||
|
||||
if response.status_code != 200:
|
||||
await invalid_query(update, query)
|
||||
|
@ -39,8 +38,8 @@ async def answer_query(update: Update, query: str, data) -> None:
|
|||
rating = format_rating(data['rating'])
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"Open in {config.get('App', 'Name')}",
|
||||
url=f"https://{main.hostname}/posts/{query}"),
|
||||
InlineKeyboardButton(f"Open in {app.name}",
|
||||
url=f"https://{app.hostname}/posts/{query}"),
|
||||
InlineKeyboardButton("View original", url=data['file_url'])
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue