Ë
    Fü´j
&  ã                  óÊ   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ erddlmZ ddlZddlmZ  G d„ de«      Zy)zProvides the User class.é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚConflict)ÚAPI_PATH)ÚReadOnlyException)ÚPreferences)ÚPRAWBase)ÚListingGenerator)ÚRedditor)Ú	Subreddit)Úcachedproperty)ÚIteratorN)Úmodelsc                  ó¨   ‡ — e Zd ZdZedd„«       Zdˆ fd„Zdd„Zdd„Zddœdd„Z	dd	„Z
d
dœdd„Zdd„Zdd„Zdd
dœ	 	 	 	 	 	 	 dd„Zdd„Zdd„Zˆ xZS )ÚUserzOThe :class:`.User` class provides methods for the currently authenticated user.c                ó,   — t        | j                  «      S )ap  Get an instance of :class:`.Preferences`.

        The preferences can be accessed as a ``dict`` like so:

        .. code-block:: python

            preferences = reddit.user.preferences()
            print(preferences["show_link_flair"])

        Preferences can be updated via:

        .. code-block:: python

            reddit.user.preferences.update(show_link_flair=True)

        The :meth:`.Preferences.update` method returns the new state of the preferences
        as a ``dict``, which can be used to check whether a change went through. Changes
        with invalid types or parameter names fail silently.

        .. code-block:: python

            original_preferences = reddit.user.preferences()
            new_preferences = reddit.user.preferences.update(invalid_param=123)
            print(original_preferences == new_preferences)  # True, no change

        )r	   Ú_reddit©Úselfs    úN/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/user.pyÚpreferenceszUser.preferences   s   € ô8 ˜4Ÿ<™<Ó(Ð(ó    c                ó(   •— t         ‰| �  |d¬«       y)zInitialize an :class:`.User` instance.

        This class is intended to be interfaced with through ``reddit.user``.

        N©Ú_data)ÚsuperÚ__init__)r   ÚredditÚ	__class__s     €r   r   zUser.__init__:   s   ø€ ô 	‰Ñ˜ tÐÕ,r   c                óF   — | j                   j                  t        d   «      S )zAReturn a :class:`.RedditorList` of blocked :class:`.Redditor`\ s.Úblocked©r   Úgetr   r   s    r   r"   zUser.blockedB   s   € à�|‰|×Ñ¤¨Ñ 3Ó4Ð4r   c                ó>   — t        | j                  t        d   fi |¤ŽS )aí  Return a :class:`.ListingGenerator` of contributor :class:`.Subreddit`\ s.

        These are subreddits in which the user is an approved user.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        To print a list of the subreddits that you are an approved user in, try:

        .. code-block:: python

            for subreddit in reddit.user.contributor_subreddits(limit=None):
                print(str(subreddit))

        Úmy_contributor©r   r   r   ©r   Úgenerator_kwargss     r   Úcontributor_subredditszUser.contributor_subredditsF   s!   € ô    §¡¬hÐ7GÑ.HÑ]ÐL\Ñ]Ð]r   N©Úuserc               ó’   — |€	t         d   n!t         d   j                  t        |«      ¬«      }| j                  j	                  |«      S )aO  Return a :class:`.RedditorList` of friends or a :class:`.Redditor` in the friends list.

        :param user: Checks to see if you are friends with the redditor. Either an
            instance of :class:`.Redditor` or a string can be given.

        :returns: A list of :class:`.Redditor`\ s, or a single :class:`.Redditor` if
            ``user`` is specified. The :class:`.Redditor` instance(s) returned also has
            friend attributes.

        :raises: An instance of :class:`.RedditAPIException` if you are not friends with
            the specified :class:`.Redditor`.

        ÚfriendsÚ	friend_v1r+   )r   ÚformatÚstrr   r$   )r   r,   Úendpoints      r   r.   zUser.friendsX   sC   € ð +/¨,”8˜IÒ&¼HÀ[Ñ<Q×<XÑ<XÔ^aÐbfÓ^gÐ<XÓ<hˆØ�|‰|×Ñ Ó)Ð)r   c                ó    — i }| j                   j                  t        d   «      d   D ]#  }t        | j                   |d   «      }|d= |||<   Œ% |S )a  Return a dictionary mapping :class:`.Subreddit`\ s to their karma.

        The returned dict contains subreddits as keys. Each subreddit key contains a
        sub-dict that have keys for ``comment_karma`` and ``link_karma``. The dict is
        sorted in descending karma order.

        .. note::

            Each key of the main dict is an instance of :class:`.Subreddit`. It is
            recommended to iterate over the dict in order to retrieve the values,
            preferably through :py:meth:`dict.items`.

        ÚkarmaÚdataÚsr)r   r$   r   r   )r   Ú	karma_mapÚrowÚ	subreddits       r   r4   z
User.karmai   s^   € ð ˆ	Ø—<‘<×#Ñ#¤H¨WÑ$5Ó6°vÑ>ò 	'ˆCÜ! $§,¡,°°D±	Ó:ˆIØ�D�	Ø#&ˆI�iÒ ð	'ð Ðr   T)Ú	use_cachec               óü   — | j                   j                  rd}t        |«      ‚d| j                  vs|s>| j                   j	                  t
        d   «      }t        | j                   |¬«      | _        | j                  S )aÛ  Return a :class:`.Redditor` instance for the authenticated user.

        :param use_cache: When ``True``, and if this function has been previously
            called, returned the cached version (default: ``True``).

        .. note::

            If you change the :class:`.Reddit` instance's authorization, you might want
            to refresh the cached value. Prefer using separate :class:`.Reddit`
            instances, however, for distinct authorizations.

        z+`user.me()` does not work in read_only modeÚ_meÚmer   )r   Ú	read_onlyr   Ú__dict__r$   r   r   r<   )r   r:   ÚmsgÚ	user_datas       r   r=   zUser.me~   sb   € ð �<‰<×!Ò!Ø?ˆCÜ# CÓ(Ð(Ø˜Ÿ™Ñ%©YØŸ™×(Ñ(¬°$©Ó8ˆIÜ §¡°IÔ>ˆDŒHØ�x‰xˆr   c                ó>   — t        | j                  t        d   fi |¤ŽS )aÛ  Return a :class:`.ListingGenerator` subreddits that the user moderates.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        To print a list of the names of the subreddits you moderate, try:

        .. code-block:: python

            for subreddit in reddit.user.moderator_subreddits(limit=None):
                print(str(subreddit))

        .. seealso::

            :meth:`.Redditor.moderated`

        Úmy_moderatorr'   r(   s     r   Úmoderator_subredditszUser.moderator_subreddits“   s    € ô$   §¡¬h°~Ñ.FÑ[ÐJZÑ[Ð[r   c                óF   — | j                   j                  t        d   «      S )z@Return a list of :class:`.Multireddit`\ s belonging to the user.Úmy_multiredditsr#   r   s    r   ÚmultiredditszUser.multireddits§   s   € à�|‰|×Ñ¤Ð):Ñ ;Ó<Ð<r   )ÚnumÚstatec               óŒ   — |j                   ||ddœ}	 | j                  j                  t        d   |¬«      S # t        $ r Y yw xY w)aK  Set the pin state of a submission on the authenticated user's profile.

        :param submission: An instance of :class:`.Submission` that will be
            pinned/unpinned.
        :param num: If specified, the slot in which the submission will be pinned into.
            If there is a submission already in the specified slot, it will be replaced.
            If ``None`` or there is not a submission in the specified slot, the first
            available slot will be used (default: ``None``). If all slots are used the
            following will occur:

            - Old Reddit:

              1. The submission in the last slot will be unpinned.
              2. The remaining pinned submissions will be shifted down a slot.
              3. The new submission will be pinned in the first slot.

            - New Reddit:

              1. The submission in the first slot will be unpinned.
              2. The remaining pinned submissions will be shifted up a slot.
              3. The new submission will be pinned in the last slot.

            .. note::

                At the time of writing (10/22/2021), there are 4 pin slots available and
                pins are in reverse order on old Reddit. If ``num`` is an invalid value,
                Reddit will ignore it and the same behavior will occur as if ``num`` is
                ``None``.

        :param state: ``True`` pins the submission, ``False`` unpins (default:
            ``True``).

        :returns: The pinned submission.

        :raises: ``prawcore.BadRequest`` when pinning a removed or deleted submission.
        :raises: ``prawcore.Forbidden`` when pinning a submission the authenticated user
            is not the author of.

        .. code-block:: python

            submission = next(reddit.user.me().submissions.new())
            reddit.user.pin(submission)

        T)ÚidrH   rI   Ú
to_profileÚsticky_submission)r5   N)Úfullnamer   Úpostr   r   )r   Ú
submissionrH   rI   r5   s        r   ÚpinzUser.pin«   sU   € ð` ×%Ñ%ØØØñ	
ˆð	Ø—<‘<×$Ñ$¤XÐ.AÑ%BÈÐ$ÓNÐNøÜò 	Ùð	ús   “#7 ·	AÁAc                ó>   — t        | j                  t        d   fi |¤ŽS )a¤  Return a :class:`.ListingGenerator` of :class:`.Subreddit`\ s the user is subscribed to.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        To print a list of the subreddits that you are subscribed to, try:

        .. code-block:: python

            for subreddit in reddit.user.subreddits(limit=None):
                print(str(subreddit))

        Úmy_subredditsr'   r(   s     r   Ú
subredditszUser.subredditså   s    € ô   §¡¬h°Ñ.GÑ\ÐK[Ñ\Ð\r   c                óF   — | j                   j                  t        d   «      S )a{  Return a :class:`.RedditorList` of trusted :class:`.Redditor`\ s.

        To display the usernames of your trusted users and the times at which you
        decided to trust them, try:

        .. code-block:: python

            trusted_users = reddit.user.trusted()
            for user in trusted_users:
                print(f"User: {user.name}, time: {user.date}")

        Útrustedr#   r   s    r   rV   zUser.trustedõ   s   € ð �|‰|×Ñ¤¨Ñ 3Ó4Ð4r   )Úreturnzmodels.Preferences)r   zpraw.RedditrW   ÚNone)rW   zlist[models.Redditor])r)   r   rW   zIterator[models.Subreddit])r,   zstr | models.Redditor | NonerW   z'list[models.Redditor] | models.Redditor)rW   z&dict[models.Subreddit, dict[str, int]])r:   ÚboolrW   zmodels.Redditor | None)rW   zlist[models.Multireddit])rP   zmodels.SubmissionrH   z
int | NonerI   rY   rW   zmodels.Submission | None)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r*   r.   r4   r=   rD   rG   rQ   rT   rV   Ú__classcell__)r    s   @r   r   r      sˆ   ø„ ÙYàò)ó ð)õ:-ó5ó^ð$ ?Cõ *ó"ð* '+õ ó*\ó(=ð
 CGÐVZñ8Ø+ð8Ø5?ð8ØOSð8à	!ó8ót]÷ 5r   r   )r]   Ú
__future__r   Útypingr   r   Úprawcorer   Ú
praw.constr   Úpraw.exceptionsr   Úpraw.modelsr	   Úpraw.models.baser
   Úpraw.models.listing.generatorr   Úpraw.models.reddit.redditorr   Úpraw.models.reddit.subredditr   Úpraw.util.cacher   Úcollections.abcr   Úprawr   r   © r   r   ú<module>rm      sC   ðÙ å "ç %å å Ý -Ý #Ý %Ý :Ý 0Ý 2Ý *áÝ(ãÝôi5ˆ8õ i5r   