Files
post_bot/.history/handlers/edit_button_20250904013103.py
Andrey K. Choi aca280b64d
Some checks failed
continuous-integration/drone Build is failing
init commit
2025-09-04 01:51:59 +09:00

23 lines
885 B
Python
Raw 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 SessionLocal
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 = SessionLocal()
button = session.query(Button).filter_by(name=name).first()
if not button:
await update.message.reply_text('Кнопка не найдена.')
session.close()
return
button.name = new_name
button.url = new_url
session.commit()
session.close()
await update.message.reply_text(f'Кнопка "{name}" изменена.')