from telegram import Update from telegram.ext import CommandHandler, ContextTypes from db import AsyncSessionLocal from models import Button async def edit_button(update: Update, context: ContextTypes.DEFAULT_TYPE): args = context.args if len(args) < 3: await update.message.reply_text('Используйте: /edit_button <название> <новое_название> <новая_ссылка>') return name, new_name, new_url = args[0], args[1], args[2] session = AsyncSessionLocal() try: result = await session.execute(Button.__table__.select().where(Button.name == name)) button = result.scalar_one_or_none() if not button: if update.message: await update.message.reply_text('Кнопка не найдена.') return button.name = new_name button.url = new_url await session.commit() from db import log_action user_id = update.effective_user.id if update.effective_user else None log_action(user_id, "edit_button", f"old_name={name}, new_name={new_name}, new_url={new_url}") if update.message: await update.message.reply_text(f'Кнопка "{name}" изменена.') finally: await session.close()