This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import CommandHandler, ContextTypes
|
||||
from db import AsyncSessionLocal
|
||||
from db import AsyncSessionLocal, log_action
|
||||
from models import Button
|
||||
|
||||
async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
@@ -10,9 +10,8 @@ async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await update.message.reply_text('Используйте: /del_button <название>')
|
||||
return
|
||||
name = args[0]
|
||||
session = AsyncSessionLocal()
|
||||
try:
|
||||
from sqlalchemy import select
|
||||
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:
|
||||
@@ -21,7 +20,7 @@ async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
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}" удалена.')
|
||||
finally:
|
||||
await session.close()
|
||||
await update.message.reply_text(f'Кнопка \"{name}\" удалена.')
|
||||
|
||||
Reference in New Issue
Block a user