async refactor & docker deploy environment
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-09-05 12:04:58 +09:00
parent 0d3bcdfc64
commit d17f0f5507
15 changed files with 361 additions and 187 deletions

View File

@@ -1,21 +1,27 @@
from telegram import Update
from telegram.ext import CommandHandler, ContextTypes
from db import SessionLocal
from db import AsyncSessionLocal
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 <название>')
if update.message:
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}" удалена.')
session = AsyncSessionLocal()
try:
from sqlalchemy import select
result = await session.execute(select(Button).where(Button.name == name))
button = result.scalar_one_or_none()
if not button:
if update.message:
await update.message.reply_text('Кнопка не найдена.')
return
await session.delete(button)
await session.commit()
if update.message:
await update.message.reply_text(f'Кнопка "{name}" удалена.')
finally:
await session.close()