28 lines
1010 B
Python
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()
|