Files
post_bot/handlers/del_button.py
Choi A.K. d17f0f5507
Some checks failed
continuous-integration/drone/push Build is failing
async refactor & docker deploy environment
2025-09-05 12:04:58 +09:00

28 lines
1010 B
Python

from telegram import Update
from telegram.ext import CommandHandler, ContextTypes
from db import AsyncSessionLocal
from models import Button
async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
args = context.args
if not args:
if update.message:
await update.message.reply_text('Используйте: /del_button <название>')
return
name = args[0]
session = AsyncSessionLocal()
try:
from sqlalchemy import select
result = await session.execute(select(Button).where(Button.name == name))
button = result.scalar_one_or_none()
if not button:
if update.message:
await update.message.reply_text('Кнопка не найдена.')
return
await session.delete(button)
await session.commit()
if update.message:
await update.message.reply_text(f'Кнопка "{name}" удалена.')
finally:
await session.close()