This commit is contained in:
21
handlers/del_button.py
Normal file
21
handlers/del_button.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import CommandHandler, ContextTypes
|
||||
from db import SessionLocal
|
||||
from models import Button
|
||||
|
||||
async def del_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
args = context.args
|
||||
if not args:
|
||||
await update.message.reply_text('Используйте: /del_button <название>')
|
||||
return
|
||||
name = args[0]
|
||||
session = SessionLocal()
|
||||
button = session.query(Button).filter_by(name=name).first()
|
||||
if not button:
|
||||
await update.message.reply_text('Кнопка не найдена.')
|
||||
session.close()
|
||||
return
|
||||
session.delete(button)
|
||||
session.commit()
|
||||
session.close()
|
||||
await update.message.reply_text(f'Кнопка "{name}" удалена.')
|
||||
Reference in New Issue
Block a user