migrations + util scripts
This commit is contained in:
40
handlers/admin_panel.py
Normal file
40
handlers/admin_panel.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import CommandHandler, CallbackQueryHandler, ConversationHandler, ContextTypes
|
||||
from db import AsyncSessionLocal
|
||||
from models import Admin, Channel, Group, Button
|
||||
|
||||
ADMIN_MENU, PREVIEW_POST = range(2)
|
||||
|
||||
async def admin_panel(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
user_id = update.effective_user.id if update.effective_user else None
|
||||
async with AsyncSessionLocal() as session:
|
||||
# Получаем каналы и группы, которыми управляет админ
|
||||
channels_result = await session.execute(Channel.__table__.select().where(Channel.admin_id == user_id))
|
||||
channels = channels_result.scalars().all()
|
||||
groups_result = await session.execute(Group.__table__.select().where(Group.admin_id == user_id))
|
||||
groups = groups_result.scalars().all()
|
||||
# Статистика
|
||||
buttons_result = await session.execute(Button.__table__.select())
|
||||
buttons = buttons_result.scalars().all()
|
||||
stats = f"Каналов: {len(channels)}\nГрупп: {len(groups)}\nКнопок: {len(buttons)}"
|
||||
text = f"<b>Ваша админ-панель</b>\n\n{stats}\n\nВаши каналы:\n" + '\n'.join([f"- {c.name}" for c in channels]) + "\n\nВаши группы:\n" + '\n'.join([f"- {g.name}" for g in groups])
|
||||
keyboard = []
|
||||
# Кнопка предпросмотра поста (можно доработать)
|
||||
keyboard.append([InlineKeyboardButton("Предпросмотр поста", callback_data="preview_post")])
|
||||
await update.message.reply_text(text, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode='HTML')
|
||||
return ADMIN_MENU
|
||||
|
||||
async def preview_post_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
query = update.callback_query
|
||||
await query.answer()
|
||||
# Здесь можно реализовать предпросмотр поста с кнопками
|
||||
await query.edit_message_text("Здесь будет предпросмотр поста с кнопками.")
|
||||
return ConversationHandler.END
|
||||
|
||||
admin_panel_conv = ConversationHandler(
|
||||
entry_points=[CommandHandler('admin', admin_panel)],
|
||||
states={
|
||||
ADMIN_MENU: [CallbackQueryHandler(preview_post_callback, pattern="preview_post")],
|
||||
},
|
||||
fallbacks=[]
|
||||
)
|
||||
Reference in New Issue
Block a user