Untitled

mail@pastecode.io avatar
unknown
python
a year ago
970 B
2
Indexable
Never
class IsSubscribe(BaseFilter):
    async def __call__(self, obj: Message, repo: Repo, config: Config, bot: Bot) -> bool:
        await repo.add_user_start(tg_id=obj.from_user.id)
        if await check_admin(obj, config):
            return True
        else:
            channels_info = await repo.get_all_channel_ids_and_links()
            return await is_user_subscribed(obj.from_user.id, bot, channels_info)
            



async def is_user_subscribed(user_id: int, bot: Bot, channels_info: List[Tuple[int, str]]) -> bool:
    for chat_id, _ in channels_info:
        try:
            member = await bot.get_chat_member(chat_id=chat_id, user_id=user_id)
            if member.status == 'left':
                return False
        except Exception as e:
            print(f"Ошибка при проверке подписки для пользователя {user_id} и канала {chat_id}: {e}")
            return False
    return True