Files
post_bot/.history/handlers/del_button_20250904013103.py
Andrey K. Choi aca280b64d
Some checks failed
continuous-integration/drone Build is failing
init commit
2025-09-04 01:51:59 +09:00

22 lines
758 B
Python

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}" удалена.')