This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
|
||||
|
||||
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import ContextTypes, ConversationHandler, CommandHandler, CallbackQueryHandler, MessageHandler, filters
|
||||
from db import AsyncSessionLocal
|
||||
@@ -90,8 +93,27 @@ async def input_url(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
except Exception as e:
|
||||
if update.message:
|
||||
await update.message.reply_text(f'Ошибка при добавлении кнопки: {e}')
|
||||
try:
|
||||
type_, obj_id = target.split('_', 1)
|
||||
obj_id = int(obj_id)
|
||||
if type_ == 'channel':
|
||||
button = Button(name=name, url=url, channel_id=obj_id)
|
||||
elif type_ == 'group':
|
||||
button = Button(name=name, url=url, group_id=obj_id)
|
||||
else:
|
||||
await update.message.reply_text('Ошибка: неверный тип объекта.')
|
||||
session.close()
|
||||
return ConversationHandler.END
|
||||
session.add(button)
|
||||
session.commit()
|
||||
from db import log_action
|
||||
user_id = update.effective_user.id if update.effective_user else None
|
||||
log_action(user_id, "add_button", f"type={type_}, obj_id={obj_id}, name={name}, url={url}")
|
||||
await update.message.reply_text('Кнопка добавлена.')
|
||||
except Exception as e:
|
||||
await update.message.reply_text(f'Ошибка при добавлении кнопки: {e}')
|
||||
finally:
|
||||
await session.close()
|
||||
session.close()
|
||||
return ConversationHandler.END
|
||||
|
||||
add_button_conv = ConversationHandler(
|
||||
@@ -102,4 +124,4 @@ add_button_conv = ConversationHandler(
|
||||
INPUT_URL: [MessageHandler(filters.TEXT & ~filters.COMMAND, input_url)],
|
||||
},
|
||||
fallbacks=[]
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user