From 25768e4c90133625685ab665e0b184e64864f03f Mon Sep 17 00:00:00 2001 From: mctaylors Date: Mon, 10 Mar 2025 15:16:00 +0300 Subject: [PATCH] refactor: add html_parser.py Signed-off-by: mctaylors --- commands.py | 14 ++++++++------ html_parser.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 html_parser.py diff --git a/commands.py b/commands.py index 1ace2ea..c2119db 100644 --- a/commands.py +++ b/commands.py @@ -1,3 +1,5 @@ +import html_parser + from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ParseMode from telegram.ext import ContextTypes @@ -5,7 +7,7 @@ from telegram.ext import ContextTypes async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text( - f"hello, i'm {context.bot.first_name}, an inline image grabber.\n\n" + f"hello, i'm {html_parser.bold(context.bot.first_name)}, an inline image grabber.\n\n" f"to get help, use /help", parse_mode=ParseMode.HTML ) @@ -13,9 +15,9 @@ async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text( - f"how to use {context.bot.first_name}\n\n" + f"{html_parser.bold(f"how to use {context.bot.first_name}")}\n\n" f"1. open your message box and type:\n" - f"@{context.bot.username} <post ID>\n" + f"{html_parser.code(f"@{context.bot.username} <post ID>")}\n" f"2. click on the box that has popped up\n" f"3. ???\n" f"4. done!", @@ -36,11 +38,11 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N reply_markup = InlineKeyboardMarkup(keyboard) await update.message.reply_text( - 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"(or other similar services).\n\n" - f"currently configured instance:\n" - f"{config.get('Service', 'Name')} ({config.get('Service', 'Domain')})", + f"{html_parser.bold("currently configured instance:")}\n" + f"{html_parser.italic(config.get('Service', 'Name'))} ({config.get('Service', 'Domain')})", parse_mode=ParseMode.HTML, reply_markup=reply_markup ) diff --git a/html_parser.py b/html_parser.py new file mode 100644 index 0000000..65b62c6 --- /dev/null +++ b/html_parser.py @@ -0,0 +1,14 @@ +def bold(s: str) -> str: + return f"{s}" + +def italic(s: str) -> str: + return f"{s}" + +def strikethrough(s: str) -> str: + return f"{s}" + +def hyperlink(s: str, href: str) -> str: + return f"{s}" + +def code(s: str) -> str: + return f"{s}" \ No newline at end of file