admin check-in
This commit is contained in:
32
alembic/versions/21c6fd6ac065_admins_checkin.py
Normal file
32
alembic/versions/21c6fd6ac065_admins_checkin.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""admins checkin
|
||||
|
||||
Revision ID: 21c6fd6ac065
|
||||
Revises: eeb6744b9452
|
||||
Create Date: 2025-09-06 08:41:08.145822
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '21c6fd6ac065'
|
||||
down_revision: Union[str, Sequence[str], None] = 'eeb6744b9452'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
@@ -20,6 +20,7 @@ from sqlalchemy import select as sa_select
|
||||
|
||||
from db import AsyncSessionLocal
|
||||
from models import Channel, Group, Button
|
||||
from models import Admin
|
||||
|
||||
|
||||
SELECT_MEDIA, SELECT_TEXT, SELECT_TARGET = range(3)
|
||||
@@ -162,14 +163,24 @@ async def select_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
# Сохраняем исходные данные БЕЗ изменений
|
||||
context.user_data["text"] = text
|
||||
context.user_data["entities"] = entities
|
||||
if update.effective_chat and hasattr(update.effective_chat, 'id'):
|
||||
context.user_data["src_chat_id"] = update.effective_chat.id
|
||||
else:
|
||||
context.user_data["src_chat_id"] = None
|
||||
context.user_data["src_msg_id"] = update.message.message_id
|
||||
|
||||
# Дальше как у тебя: выбор канала/группы
|
||||
from sqlalchemy import select as sa_select
|
||||
user = update.effective_user
|
||||
if not user or not hasattr(user, 'id'):
|
||||
await update.message.reply_text('Ошибка: не удалось определить пользователя.')
|
||||
return ConversationHandler.END
|
||||
admin_tg_id = user.id
|
||||
async with AsyncSessionLocal() as session:
|
||||
channels = (await session.execute(sa_select(Channel))).scalars().all()
|
||||
groups = (await session.execute(sa_select(Group))).scalars().all()
|
||||
admin_obj = (await session.execute(sa_select(Admin).where(Admin.tg_id == admin_tg_id))).scalar_one_or_none()
|
||||
admin_id = admin_obj.id if admin_obj else None
|
||||
channels = (await session.execute(sa_select(Channel).where(Channel.admin_id == admin_id))).scalars().all() if admin_id is not None else []
|
||||
groups = (await session.execute(sa_select(Group).where(Group.admin_id == admin_id))).scalars().all() if admin_id is not None else []
|
||||
|
||||
keyboard = []
|
||||
for c in channels:
|
||||
@@ -207,7 +218,7 @@ async def select_target(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
markup = InlineKeyboardMarkup([[InlineKeyboardButton(str(b.name), url=str(b.url))] for b in buttons]) if buttons else None
|
||||
chat_id = group.link if group else None
|
||||
|
||||
if not chat_id:
|
||||
if chat_id is None:
|
||||
await query.edit_message_text('Ошибка: объект не найден.')
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
Reference in New Issue
Block a user