Files
post_bot/handlers/admin_panel.py
Choi A.K. f35113e5c8
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
migrations + util scripts
2025-09-05 13:54:59 +09:00

41 lines
2.3 KiB
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, 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=[]
)