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
10
commands.py
10
commands.py
|
@ -3,8 +3,7 @@ from telegram.constants import ParseMode
|
|||
from telegram.ext import ContextTypes
|
||||
|
||||
import html_parser
|
||||
import main
|
||||
from main import config
|
||||
from config import *
|
||||
|
||||
|
||||
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
|
@ -29,11 +28,10 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
|
||||
async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
reply_markup = None
|
||||
source_url = config.get('General', 'SourceUrl')
|
||||
if source_url.startswith('http://') or source_url.startswith('https://'):
|
||||
if general.sourceurl is not None:
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(f"source code", url=source_url)
|
||||
InlineKeyboardButton(f"source code", url=general.sourceurl)
|
||||
]
|
||||
]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
@ -43,7 +41,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'))} ({main.hostname})",
|
||||
f"{html_parser.italic(app.name)} ({app.hostname})",
|
||||
parse_mode=ParseMode.HTML,
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue