from telegram import Update from telegram.constants import ChatType, ParseMode from telegram.ext import ContextTypes from app.bot.messages import START, HELP, NO_CHATS from app.db.session import get_session from app.db.models import User, Chat async def start(update: Update, ctx: ContextTypes.DEFAULT_TYPE): # register user with get_session() as s: u = s.query(User).filter_by(tg_id=update.effective_user.id).first() if not u: u = User(tg_id=update.effective_user.id, name=update.effective_user.full_name) s.add(u); s.commit() await update.effective_message.reply_text(START) async def help_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE): await update.effective_message.reply_text(HELP) async def groups_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE): with get_session() as s: u = s.query(User).filter_by(tg_id=update.effective_user.id).first() if not u: await update.effective_message.reply_text(NO_CHATS) return chats = s.query(Chat).filter_by(owner_user_id=u.id).order_by(Chat.created_at.desc()).all() if not chats: await update.effective_message.reply_text(NO_CHATS) return lines = [] for c in chats: icon = "📣" if c.type == ChatType.CHANNEL else "👥" post = "✅ могу публиковать" if c.can_post else "⚠️ нет прав публикации" lines.append(f"{icon} {c.title or c.chat_id} — {post}") await update.effective_message.reply_text("\n".join(lines), parse_mode=ParseMode.HTML)