o
    2gEB                     @  s   d 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 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mZ erJddlZG dd deeeeZG dd dZdS )zProvide the Redditor class.    )annotations)dumps)TYPE_CHECKINGAny	Generator   )API_PATH)_deprecate_args)cachedproperty   )RedditorListingMixin)stream_generator   )
RedditBase)FullnameMixinMessageableMixinNc                      s*  e Zd ZdZdZedJd	d
ZedKddZedLddZ	e
dMddZe
dMddZ			dNdO fddZdP fdd Z fd!d"Zd#d$ ZdQd%d&ZdRd(d)Zd*d+ Zd,d- Zed.dd/dSd0d1ZdTd3d4Zed5d6d7dUd9d:ZdVd<d=ZdWd?d@ZdXdBdCZdDdE ZdFdG ZdHdI Z  ZS )Y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 dictionary of
                                        additional attributes. See below.
    ``subreddit["banner_img"]``         The URL of the user-subreddit banner.
    ``subreddit["name"]``               The fullname of the user-subreddit.
    ``subreddit["over_18"]``            Whether or not the user-subreddit is NSFW.
    ``subreddit["public_description"]`` The public description of the user-subreddit.
    ``subreddit["subscribers"]``        The number of users subscribed to the
                                        user-subreddit.
    ``subreddit["title"]``              The title of the user-subreddit.
    =================================== ================================================

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

    nameredditpraw.Redditdatadict[str, Any]returnRedditor | Nonec                 C  s   |dkrdS | ||S )zDReturn an instance of :class:`.Redditor`, or ``None`` from ``data``.z	[deleted]N )clsr   r   r   r   S/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/redditor.py	from_dataO   s   
zRedditor.from_datapraw.models.RedditorModNotesc                 C  s   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   r   r   r   notesV   s   zRedditor.notes*praw.models.reddit.redditor.RedditorStreamc                 C  s   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"   r   r   r   streamn   s   zRedditor.streamstrc                 C  s   | j jjd S )zReturn the class's kind.redditor)r!   configkindsr&   r   r   r   _kind   s   zRedditor._kindc                 C  s   t d j| dS )Nuserr-   )r   formatr&   r   r   r   _path   s   zRedditor._pathN
str | Nonefullname_datadict[str, Any] | Nonec                   sp   |||f ddkrd}t||rt|trd|v sJ dd| _|r(|| _n|r-|| _t j||dd dS )	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.

        Nr   z?Exactly one of 'name', 'fullname', or '_data' must be provided.r   zPlease file a bug with PRAW.T	_fullname)r3   _extra_attribute_to_check)	count	TypeError
isinstancedict_listing_use_sortr   r5   super__init__)r"   r   r   r2   r3   msg	__class__r   r   r=      s   
zRedditor.__init__valuer   c                   s8   |dkr|rddl m} || j|d}t || dS )z"Objectify the subreddit attribute.	subredditr   )UserSubreddit)r   r3   N)user_subredditrC   r!   r<   __setattr__)r"   r   rA   rC   r?   r   r   rE      s   zRedditor.__setattr__c                   s>   |   }|d }t| | j|d}| j|j t   d S )Nr   )r3   )_fetch_datatyper!   __dict__updater<   _fetch)r"   r   otherr?   r   r   rJ      s
   zRedditor._fetchc                 C  s(   t | dr| | j| _dd| jid fS )Nr5   
user_aboutr-   )hasattr_fetch_usernamer5   r   r&   r   r   r   _fetch_info   s   
zRedditor._fetch_infoc                 C  s    | j jtd d|id| d S )Nuser_by_fullnameidsparamsr   )r!   getr   )r"   r2   r   r   r   rN      s
   zRedditor._fetch_usernamemethodc                C  s*   t d j| d}| jjt|||d d S )N	friend_v1r.   )r   rU   path)r   r/   r!   requestr   )r"   r   rU   urlr   r   r   _friend   s   zRedditor._friendc                 C     | j jtd d| jid dS )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   rR   Nr!   postr   r   r&   r   r   r   block   s   zRedditor.blockc                 C  r[   )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   Nr]   r&   r   r   r   distrust   s   zRedditor.distrustnote)rc   c                C  s   | j |rd|ini dd dS )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")

        rc   PUTr   rU   N)rZ   )r"   rc   r   r   r   friend   s   zRedditor.friendpraw.models.Redditorc                 C     | j td j| d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

        rV   r.   r!   rT   r   r/   r&   r   r   r   friend_info  s   zRedditor.friend_infomonthsr   )rk   intc                C  s@   |dk s|dkrd}t || jjtd j| dd|id dS )	a  Gild the :class:`.Redditor`.

        :param months: Specifies the number of months to gild up to 36 (default: ``1``).

        For example, to gild :class:`.Redditor` u/spez for 1 month:

        .. code-block:: python

            reddit.redditor("spez").gild(months=1)

        r   $   zmonths must be between 1 and 36	gild_user)usernamerk   ra   N)r8   r!   r^   r   r/   )r"   rk   r>   r   r   r   gild  s   
zRedditor.gildlist[praw.models.Subreddit]c                 C  s   | j td j| dp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.   ri   r&   r   r   r   rr   )  s   -zRedditor.moderatedlist[praw.models.Multireddit]c                 C  rh   )zReturn a list of the redditor's public multireddits.

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

        .. code-block:: python

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

        multireddit_userr.   ri   r&   r   r   r   multiredditsX  s   
zRedditor.multiredditslist[praw.models.Trophy]c                 C  s   t | jtd j| d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!   rT   r   r/   r&   r   r   r   rw   d  s   zRedditor.trophiesc                 C  r[   )aq  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("AaronSw").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   ra   Nr]   r&   r   r   r   trustw  s   %zRedditor.trustc                 C  s>   | j j jt| dd}td jdd}| j j||d dS )zUnblock the :class:`.Redditor`.

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

        .. code-block:: python

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

        enemy)	containerr   rG   unfriendall)rB   ra   N)r!   r-   mer2   r(   r   r/   r^   )r"   r   rY   r   r   r   unblock  s   zRedditor.unblockc                 C  s   | j dt| idd dS )zUnfriend the :class:`.Redditor`.

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

        .. code-block:: python

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

        idDELETEre   N)rZ   r(   r&   r   r   r   r}     s   
zRedditor.unfriend)r   r   r   r   r   r   )r   r   )r   r$   )r   r(   )NNN)r   r   r   r1   r2   r1   r3   r4   )r   r(   rA   r   )r2   r(   )r   r   rU   r(   )rc   r(   )r   rg   )rk   rl   )r   rq   )r   rs   )r   rv   ) __name__
__module____qualname____doc__	STR_FIELDclassmethodr   r
   r#   r'   propertyr,   r0   r=   rE   rJ   rO   rN   rZ   r_   rb   r	   rf   rj   rp   rr   ru   rw   rz   r   r}   __classcell__r   r   r?   r   r      sF    8




/
'r   c                   @  s.   e Zd ZdZdddZdd
dZdddZdS )r%   z(Provides submission and comment streams.r)   rg   c                 C  s
   || _ dS )z}Initialize a :class:`.RedditorStream` instance.

        :param redditor: The redditor associated with the streams.

        N)r)   )r"   r)   r   r   r   r=     s   
zRedditorStream.__init__stream_optionsstr | int | dict[str, str]r   *Generator[praw.models.Comment, None, None]c                 K     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"   r   r   r   r   r        zRedditorStream.comments-Generator[praw.models.Submission, None, None]c                 K  r   )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   r   r   r   r     r   zRedditorStream.submissionsN)r)   rg   )r   r   r   r   )r   r   r   r   )r   r   r   r   r=   r   r   r   r   r   r   r%     s
    

r%   )r   
__future__r   jsonr   typingr   r   r   constr   utilr	   
util.cacher
   listing.mixinsr   r   baser   mixinsr   r   praw.modelsprawr   r%   r   r   r   r   <module>   s$       ,