Files
post_bot/handlers/del_button.py
Andrey K. Choi 9793648ee3
Some checks failed
continuous-integration/drone/push Build is failing
security, audit, fom features
2025-09-06 05:03:45 +09:00

27 lines
1.1 KiB
Python

from telegram import Update
from telegram.ext import CommandHandler, ContextTypes
from db import AsyncSessionLocal, log_action
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]
from sqlalchemy import select
async with AsyncSessionLocal() as session:
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()
user_id = update.effective_user.id if update.effective_user else None
await log_action(user_id, "del_button", f"name={name}")
if update.message:
await update.message.reply_text(f'Кнопка \"{name}\" удалена.')