Ë
    Fü´j-=  ã            	      óÖ   — d Z ddlm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mZ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eeee«      Z G d„ d«      Zy)zProvide the Redditor class.é    )Úannotations)Údumps)ÚTYPE_CHECKINGÚAny)ÚAPI_PATH)ÚRedditorListingMixin)Ú
RedditBase)ÚCreatedMixinÚFullnameMixinÚMessageableMixin)Ústream_generator)Úcachedproperty)ÚIteratorN)Úmodelsc                  ó"  ‡ — e Zd ZdZdZedd„«       Zedd„«       Zedd„«       Z	e
dd„«       Ze
dd„«       Z	 	 	 d	 	 	 	 	 	 	 	 	 dˆ fd	„Zd ˆ fd
„Zd!ˆ fd„Zd"d„Zd#d„Zd$d„Zd!d„Zd!d„Zddœd%d„Zd&d„Zd'd„Zd(d„Zd)d„Zd!d„Zd!d„Zd!d„Zˆ xZS )*ÚRedditora£  A class representing the users of Reddit.

    .. include:: ../../typical_attributes.rst

    .. note::

        Shadowbanned accounts are treated the same as non-existent accounts, meaning
        that they will not have any attributes.

    .. note::

        Suspended/banned accounts will only return the ``name`` and ``is_suspended``
        attributes.

    ====================== =============================================================
    Attribute              Description
    ====================== =============================================================
    ``comment_karma``      The comment karma for the :class:`.Redditor`.
    ``comments``           Provide an instance of :class:`.SubListing` for comment
                           access.
    ``submissions``        Provide an instance of :class:`.SubListing` for submission
                           access.
    ``created_utc``        Time the account was created, represented in `Unix Time`_.
    ``has_verified_email`` Whether or not the :class:`.Redditor` has verified their
                           email.
    ``icon_img``           The url of the Redditors' avatar.
    ``id``                 The ID of the :class:`.Redditor`.
    ``is_employee``        Whether or not the :class:`.Redditor` is a Reddit employee.
    ``is_friend``          Whether or not the :class:`.Redditor` is friends with the
                           authenticated user.
    ``is_mod``             Whether or not the :class:`.Redditor` mods any subreddits.
    ``is_gold``            Whether or not the :class:`.Redditor` has active Reddit
                           Premium status.
    ``is_suspended``       Whether or not the :class:`.Redditor` is currently suspended.
    ``link_karma``         The link karma for the :class:`.Redditor`.
    ``name``               The Redditor's username.
    ``subreddit``          If the :class:`.Redditor` has created a user-subreddit,
                           provides a :class:`.UserSubreddit` with additional
                           attributes.
    ====================== =============================================================

    .. _unix time: https://en.wikipedia.org/wiki/Unix_time

    Únamec                ó    — |dk(  ry | ||«      S )zDReturn an instance of :class:`.Redditor`, or ``None`` from ``data``.z	[deleted]N© )ÚclsÚredditÚdatas      úY/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/reddit/redditor.pyÚ	from_datazRedditor.from_dataF   s   € ð �;ÒØÙ�6˜4Ó Ð ó    c                ó4   — ddl m}  || j                  | «      S )a  Provide an instance of :class:`.RedditorModNotes`.

        This provides an interface for managing moderator notes for a redditor.

        .. note::

            The authenticated user must be a moderator of the provided subreddit(s).

        For example, all the notes for u/spez in r/test can be iterated through like so:

        .. code-block:: python

            redditor = reddit.redditor("spez")

            for note in redditor.notes.subreddits("test"):
                print(f"{note.label}: {note.note}")

        r   )ÚRedditorModNotes)Úpraw.models.mod_notesr   Ú_reddit)Úselfr   s     r   ÚnoteszRedditor.notesM   s   € õ( 	;á §¡¨dÓ3Ð3r   c                ó   — t        | «      S )aR  Provide an instance of :class:`.RedditorStream`.

        Streams can be used to indefinitely retrieve new comments made by a redditor,
        like:

        .. code-block:: python

            for comment in reddit.redditor("spez").stream.comments():
                print(comment)

        Additionally, new submissions can be retrieved via the stream. In the following
        example all submissions are fetched via the redditor u/spez:

        .. code-block:: python

            for submission in reddit.redditor("spez").stream.submissions():
                print(submission)

        )ÚRedditorStream©r    s    r   ÚstreamzRedditor.streame   s   € ô* ˜dÓ#Ð#r   c                óH   — | j                   j                  j                  d   S )zThe class's kind.Úredditor)r   ÚconfigÚkindsr$   s    r   Ú_kindzRedditor._kind|   s   € ð �|‰|×"Ñ"×(Ñ(¨Ñ4Ð4r   c                ó4   — t         d   j                  | ¬«      S )NÚuser©r,   )r   Úformatr$   s    r   Ú_pathzRedditor._path�   s   € ä˜Ñ×&Ñ&¨DÐ&Ó1Ð1r   Nc                óâ   •— t        d„ |||fD «       «      dk7  rd}t        |«      ‚|rt        |t        «      rd|v sJ d«       ‚d| _        |r|| _        n	|r|| _        t        ‰| �!  ||d¬«       y	)
a7  Initialize a :class:`.Redditor` instance.

        :param reddit: An instance of :class:`.Reddit`.
        :param name: The name of the redditor.
        :param fullname: The fullname of the redditor, starting with ``t2_``.

        Exactly one of ``name``, ``fullname`` or ``_data`` must be provided.

        c              3  ó&   K  — | ]	  }|€Œd–— Œ y ­w)Né   r   )Ú.0Úvalues     r   ú	<genexpr>z$Redditor.__init__.<locals>.<genexpr>•   s   è ø€ ÒK�U¸Ñ9JŒqÑKùs   ‚Šr2   z?Exactly one of 'name', 'fullname', or '_data' must be provided.r   zPlease file a bug with PRAW.TÚ	_fullname)Ú_dataÚ_extra_attribute_to_checkN)	ÚsumÚ	TypeErrorÚ
isinstanceÚdictÚ_listing_use_sortr   r6   ÚsuperÚ__init__)r    r   r   Úfullnamer7   ÚmsgÚ	__class__s         €r   r?   zRedditor.__init__…   s�   ø€ ô  ÑK˜t X¨uÐ5ÔKÓKÈqÒPØSˆCÜ˜C“.Ð Ùä˜5¤$Ô'¨F°e©Oð.à-ó.Ø;à!%ˆÔÙØˆD�IÙØ%ˆDŒNÜ‰Ñ˜ uÈÐÕTr   c                óh   •— |dk(  r|rddl m}  ||| j                  ¬«      }t        ‰| �  ||«       y)z"Objectify the subreddit attribute.Ú	subredditr   )ÚUserSubreddit)r7   r   N)Ú!praw.models.reddit.user_subredditrE   r   r>   Ú__setattr__)r    r   r4   rE   rB   s       €r   rG   zRedditor.__setattr__£   s/   ø€ à�;Ò¡5ÝGá!¨°d·l±lÔCˆEÜ‰Ñ˜D %Õ(r   c                ó(  •— t        | d«      r | j                  | j                  «      | _        | j	                  «       }|d   } t        | «      | j                  |¬«      }| j                  j                  |j                  «       t        ‰| �)  «        y )Nr6   r   )r7   )ÚhasattrÚ_fetch_usernamer6   r   Ú_fetch_dataÚtyper   Ú__dict__Úupdater>   Ú_fetch)r    r   ÚotherrB   s      €r   rO   zRedditor._fetch«   sp   ø€ Ü�4˜Ô%Ø×,Ñ,¨T¯^©^Ó<ˆDŒIØ×ÑÓ!ˆØ�F‰|ˆØ”�T“
˜4Ÿ<™<¨tÔ4ˆØ�‰×Ñ˜UŸ^™^Ô,Ü‰‰Õr   c                ó$   — dd| j                   id fS )NÚ
user_aboutr,   )r   r$   s    r   Ú_fetch_infozRedditor._fetch_info´   s   € Ø˜f d§i¡iÐ0°$Ð6Ð6r   c                óZ   — | j                   j                  t        d   d|i¬«      |   d   S )NÚuser_by_fullnameÚids©Úparamsr   )r   Úgetr   )r    r@   s     r   rJ   zRedditor._fetch_username·   s3   € Ø�|‰|×Ñ¤Ð);Ñ <ÀeÈXÐEVÐÓWÐX`ÑaÐbhÑiÐir   c               ó„   — t         d   j                  | ¬«      }| j                  j                  t	        |«      ||¬«       y )NÚ	friend_v1r-   )r   ÚmethodÚpath)r   r.   r   Úrequestr   )r    r   r\   Úurls       r   Ú_friendzRedditor._friendº   s7   € Ü�{Ñ#×*Ñ*°Ð*Ó5ˆØ�‰×Ñ¤%¨£+°fÀ3ÐÕGr   c                ód   — | j                   j                  t        d   d| j                  i¬«       y)aF  Block the :class:`.Redditor`.

        For example, to block :class:`.Redditor` u/spez:

        .. code-block:: python

            reddit.redditor("spez").block()

        .. note::

            Blocking a trusted user will remove that user from your trusted list.

        .. seealso::

            :meth:`.trust`

        Ú
block_userr   rW   N©r   Úpostr   r   r$   s    r   ÚblockzRedditor.block¾   s)   € ð$ 	�‰×Ñœ( <Ñ0¸&À$Ç)Á)Ð9LÐÕMr   c                ód   — | j                   j                  t        d   d| j                  i¬«       y)a  Remove the :class:`.Redditor` from your whitelist of trusted users.

        For example, to remove :class:`.Redditor` u/spez from your whitelist:

        .. code-block:: python

            reddit.redditor("spez").distrust()

        .. seealso::

            :meth:`.trust`

        Úremove_whitelistedr   ©r   Nrc   r$   s    r   ÚdistrustzRedditor.distrustÒ   s*   € ð 	�‰×Ñœ(Ð#7Ñ8ÀÈÏ	É	Ð?RÐÕSr   )Únotec               ó6   — | j                  |rd|ini d¬«       y)a  Friend the :class:`.Redditor`.

        :param note: A note to save along with the relationship. Requires Reddit Premium
            (default: ``None``).

        Calling this method subsequent times will update the note.

        For example, to friend u/spez:

        .. code-block:: python

            reddit.redditor("spez").friend()

        To add a note to the friendship (requires Reddit Premium):

        .. code-block:: python

            reddit.redditor("spez").friend(note="My favorite admin")

        rj   ÚPUT©r   r\   N)r`   )r    rj   s     r   ÚfriendzRedditor.friendâ   s   € ð* 	�‰©D˜6 4™.°bÀˆÕGr   c                óf   — | j                   j                  t        d   j                  | ¬«      «      S )aÈ  Return a :class:`.Redditor` instance with specific friend-related attributes.

        :returns: A :class:`.Redditor` instance with fields ``date``, ``id``, and
            possibly ``note`` if the authenticated user has Reddit Premium.

        For example, to get the friendship information of :class:`.Redditor` u/spez:

        .. code-block:: python

            info = reddit.redditor("spez").friend_info
            friend_data = info.date

        r[   r-   ©r   rY   r   r.   r$   s    r   Úfriend_infozRedditor.friend_infoù   s,   € ð �|‰|×Ñ¤¨Ñ 5× <Ñ <À$Ð <Ó GÓHÐHr   c                ón   — | j                   j                  t        d   j                  | ¬«      «      xs g S )aÿ  Return a list of the redditor's moderated subreddits.

        :returns: A list of :class:`.Subreddit` objects. Return ``[]`` if the redditor
            has no moderated subreddits.

        :raises: ``prawcore.ServerError`` in certain circumstances. See the note below.

        .. note::

            The redditor's own user profile subreddit will not be returned, but other
            user profile subreddits they moderate will be returned.

        Usage:

        .. code-block:: python

            for subreddit in reddit.redditor("spez").moderated():
                print(subreddit.display_name)
                print(subreddit.title)

        .. note::

            A ``prawcore.ServerError`` exception may be raised if the redditor moderates
            a large number of subreddits. If that happens, try switching to
            :ref:`read-only mode <read_only_application>`. For example,

            .. code-block:: python

                reddit.read_only = True
                for subreddit in reddit.redditor("reddit").moderated():
                    print(str(subreddit))

            It is possible that requests made in read-only mode will also raise a
            ``prawcore.ServerError`` exception.

            When used in read-only mode, this method does not retrieve information about
            subreddits that require certain special permissions to access, e.g., private
            subreddits and premium-only subreddits.

        .. seealso::

            :meth:`.User.moderator_subreddits`

        Ú	moderatedr-   rp   r$   s    r   rs   zRedditor.moderated	  s2   € ðZ �|‰|×Ñ¤¨Ñ 5× <Ñ <À$Ð <Ó GÓHÒNÈBÐNr   c                óf   — | j                   j                  t        d   j                  | ¬«      «      S )zèReturn a list of the redditor's public multireddits.

        For example, to get :class:`.Redditor` u/spez's multireddits:

        .. code-block:: python

            multireddits = reddit.redditor("spez").multireddits()

        Úmultireddit_userr-   rp   r$   s    r   ÚmultiredditszRedditor.multireddits8  s-   € ð �|‰|×Ñ¤Ð);Ñ <× CÑ CÈÐ CÓ NÓOÐOr   c                óx   — t        | j                  j                  t        d   j	                  | ¬«      «      «      S )a¯  Return a list of the redditor's trophies.

        :returns: A list of :class:`.Trophy` objects. Return ``[]`` if the redditor has
            no trophies.

        :raises: :class:`.RedditAPIException` if the redditor doesn't exist.

        Usage:

        .. code-block:: python

            for trophy in reddit.redditor("spez").trophies():
                print(trophy.name)
                print(trophy.description)

        Útrophiesr-   )Úlistr   rY   r   r.   r$   s    r   rx   zRedditor.trophiesD  s1   € ô" �D—L‘L×$Ñ$¤X¨jÑ%9×%@Ñ%@ÀdÐ%@Ó%KÓLÓMÐMr   c                ód   — | j                   j                  t        d   d| j                  i¬«       y)an  Add the :class:`.Redditor` to your whitelist of trusted users.

        Trusted users will always be able to send you PMs.

        Example usage:

        .. code-block:: python

            reddit.redditor("spez").trust()

        Use the ``accept_pms`` parameter of :meth:`.Preferences.update` to toggle your
        ``accept_pms`` setting between ``"everyone"`` and ``"whitelisted"``. For
        example:

        .. code-block:: python

            # Accept private messages from everyone:
            reddit.user.preferences.update(accept_pms="everyone")
            # Only accept private messages from trusted users:
            reddit.user.preferences.update(accept_pms="whitelisted")

        You may trust a user even if your ``accept_pms`` setting is switched to
        ``"everyone"``.

        .. note::

            You are allowed to have a user on your blocked list and your friends list at
            the same time. However, you cannot trust a user who is on your blocked list.

        .. seealso::

            - :meth:`.distrust`
            - :meth:`.Preferences.update`
            - :meth:`.trusted`

        Úadd_whitelistedr   rh   Nrc   r$   s    r   ÚtrustzRedditor.trustW  s+   € ðJ 	�‰×Ñœ(Ð#4Ñ5¸VÀTÇYÁYÐ<OÐÕPr   c                óò   — | j                   j                  j                  «       }|€J ‚|j                  t	        | «      ddœ}t
        d   j                  d¬«      }| j                   j                  ||¬«       y)z´Unblock the :class:`.Redditor`.

        For example, to unblock :class:`.Redditor` u/spez:

        .. code-block:: python

            reddit.redditor("spez").unblock()

        NÚenemy)Ú	containerr   rL   ÚunfriendÚall)rD   rh   )r   r,   Úmer@   Ústrr   r.   rd   )r    r‚   r   r_   s       r   ÚunblockzRedditor.unblock~  so   € ð �\‰\×Ñ×!Ñ!Ó#ˆØˆ~Ðˆ~àŸ™Ü˜“IØñ
ˆô
 �zÑ"×)Ñ)°EÐ)Ó:ˆØ�‰×Ñ˜# DÐÕ)r   c                ó@   — | j                  dt        | «      id¬«       y)z·Unfriend the :class:`.Redditor`.

        For example, to unfriend :class:`.Redditor` u/spez:

        .. code-block:: python

            reddit.redditor("spez").unfriend()

        ÚidÚDELETErm   N)r`   rƒ   r$   s    r   r€   zRedditor.unfriend’  s   € ð 	�‰˜4¤ T£Ð+°HˆÕ=r   )r   úpraw.Redditr   rƒ   ÚreturnzRedditor | None)r‰   zmodels.RedditorModNotes)r‰   r#   )r‰   rƒ   )NNN)
r   rˆ   r   ú
str | Noner@   rŠ   r7   zdict[str, Any] | Noner‰   ÚNone)r   rƒ   r4   r   r‰   r‹   )r‰   r‹   )r‰   z tuple[str, dict[str, str], None])r@   rƒ   r‰   rƒ   )r   zdict[str, Any]r\   rƒ   r‰   r‹   )rj   rŠ   r‰   r‹   )r‰   úmodels.Redditor)r‰   zlist[models.Subreddit])r‰   zlist[models.Multireddit])r‰   zlist[models.Trophy])Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	STR_FIELDÚclassmethodr   r   r!   r%   Úpropertyr*   r/   r?   rG   rO   rS   rJ   r`   re   ri   rn   rq   rs   rv   rx   r|   r„   r€   Ú__classcell__)rB   s   @r   r   r      s  ø„ ñ+ðZ €Iàò!ó ð!ð ò4ó ð4ð. ò$ó ð$ð, ò5ó ð5ð ò2ó ð2ð  Ø#Ø'+ðUàðUð ðUð ð	Uð
 %ðUð 
õUõ<)õó7ójóHóNó(Tð  ,0õ Hó.Ió -Oó^
PóNó&%QóN*÷(
>r   r   c                  ó(   — e Zd ZdZdd„Zdd„Zdd„Zy)	r#   z(Provides submission and comment streams.c                ó   — || _         y)z}Initialize a :class:`.RedditorStream` instance.

        :param redditor: The redditor associated with the streams.

        N)r'   )r    r'   s     r   r?   zRedditorStream.__init__¢  s   € ð !ˆ�r   c                óV   — t        | j                  j                  j                  fi |¤ŽS )a¿  Yield new comments as they become available.

        Comments are yielded oldest first. Up to 100 historical comments will initially
        be returned.

        Keyword arguments are passed to :func:`.stream_generator`.

        For example, to retrieve all new comments made by redditor u/spez, try:

        .. code-block:: python

            for comment in reddit.redditor("spez").stream.comments():
                print(comment)

        )r   r'   ÚcommentsÚnew©r    Ústream_optionss     r   r˜   zRedditorStream.commentsª  s$   € ô    §¡× 6Ñ 6× :Ñ :ÑM¸nÑMÐMr   c                óV   — t        | j                  j                  j                  fi |¤ŽS )aÔ  Yield new submissions as they become available.

        Submissions are yielded oldest first. Up to 100 historical submissions will
        initially be returned.

        Keyword arguments are passed to :func:`.stream_generator`.

        For example, to retrieve all new submissions made by redditor u/spez, try:

        .. code-block:: python

            for submission in reddit.redditor("spez").stream.submissions():
                print(submission)

        )r   r'   Úsubmissionsr™   rš   s     r   r�   zRedditorStream.submissions¼  s$   € ô    §¡× 9Ñ 9× =Ñ =ÑPÀÑPÐPr   N)r'   rŒ   r‰   r‹   )r›   r   r‰   zIterator[models.Comment])r›   r   r‰   zIterator[models.Submission])r�   rŽ   r�   r�   r?   r˜   r�   r   r   r   r#   r#   Ÿ  s   „ Ù2ó!óNô$Qr   r#   )r�   Ú
__future__r   Újsonr   Útypingr   r   Ú
praw.constr   Úpraw.models.listing.mixinsr   Úpraw.models.reddit.baser	   Úpraw.models.reddit.mixinsr
   r   r   Úpraw.models.utilr   Úpraw.util.cacher   Úcollections.abcr   Úprawr   r   r#   r   r   r   ú<module>r©      sX   ðÙ !å "å ß %å Ý ;Ý .ß SÑ SÝ -Ý *áÝ(ãÝôF>ÐÐ!5°}ÀlÐT^ô F>÷R-Qò -Qr   