danbooru-bot/commands.py
mctaylors 5262975275
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>
2025-03-26 20:29:44 +03:00

47 lines
1.7 KiB
Python

from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode
from telegram.ext import ContextTypes
import html_parser
from config import *
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(
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
)
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(
f"{html_parser.bold(f"how to use {context.bot.first_name}")}\n\n"
f"1. open your message box and type:\n"
f"{html_parser.code(f"@{context.bot.username} &lt;post ID&gt;")}\n"
f"2. click on the box that has popped up\n"
f"3. ???\n"
f"4. done!",
parse_mode=ParseMode.HTML
)
async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
reply_markup = None
if general.sourceurl is not None:
keyboard = [
[
InlineKeyboardButton(f"source code", url=general.sourceurl)
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
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"{html_parser.bold("currently configured instance:")}\n"
f"{html_parser.italic(app.name)} ({app.hostname})",
parse_mode=ParseMode.HTML,
reply_markup=reply_markup
)