from telegram import Update
from telegram.ext import CommandHandler, ContextTypes
from db import SessionLocal
from models import Button

async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
    args = context.args
    if not args:
        await update.message.reply_text('Используйте: /del_button <название>')
        return
    name = args[0]
    session = SessionLocal()
    button = session.query(Button).filter_by(name=name).first()
    if not button:
        await update.message.reply_text('Кнопка не найдена.')
        session.close()
        return
    session.delete(button)
    session.commit()
    session.close()
    await update.message.reply_text(f'Кнопка "{name}" удалена.')
