Files
post_bot/handlers/edit_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

27 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
if update.message:
await update.message.reply_text(f'Кнопка "{name}" изменена.')
finally:
await session.close()