aboutsummaryrefslogtreecommitdiff
path: root/discord/user.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-04 10:09:25 -0400
committerRapptz <[email protected]>2021-04-04 10:15:30 -0400
commit54288879e28cc63eefce33311ec393a4eed476c4 (patch)
tree5bada5e0d4f1c997773d7216d14b3338ac76f1fa /discord/user.py
parentRemove asyncio.Task subclass in preference to task names (diff)
downloaddiscord.py-54288879e28cc63eefce33311ec393a4eed476c4.tar.xz
discord.py-54288879e28cc63eefce33311ec393a4eed476c4.zip
Remove userbot functionality
This has a lot of legacy and cruft so there may be some stuff I've missed but this first pass is enough to get a clear separation.
Diffstat (limited to 'discord/user.py')
-rw-r--r--discord/user.py558
1 files changed, 7 insertions, 551 deletions
diff --git a/discord/user.py b/discord/user.py
index 25377b78..fec9bdc0 100644
--- a/discord/user.py
+++ b/discord/user.py
@@ -22,62 +22,12 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
-from collections import namedtuple
-
import discord.abc
from .flags import PublicUserFlags
-from .utils import snowflake_time, _bytes_to_base64_data, parse_time
-from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse, PremiumType, try_enum
-from .errors import ClientException
+from .utils import snowflake_time, _bytes_to_base64_data
+from .enums import DefaultAvatar, try_enum
from .colour import Colour
from .asset import Asset
-from .utils import deprecated
-
-class Profile(namedtuple('Profile', 'flags user mutual_guilds connected_accounts premium_since')):
- __slots__ = ()
-
- @property
- def nitro(self):
- return self.premium_since is not None
-
- premium = nitro
-
- def _has_flag(self, o):
- v = o.value
- return (self.flags & v) == v
-
- @property
- def staff(self):
- return self._has_flag(UserFlags.staff)
-
- @property
- def partner(self):
- return self._has_flag(UserFlags.partner)
-
- @property
- def bug_hunter(self):
- return self._has_flag(UserFlags.bug_hunter)
-
- @property
- def early_supporter(self):
- return self._has_flag(UserFlags.early_supporter)
-
- @property
- def hypesquad(self):
- return self._has_flag(UserFlags.hypesquad)
-
- @property
- def hypesquad_houses(self):
- flags = (UserFlags.hypesquad_bravery, UserFlags.hypesquad_brilliance, UserFlags.hypesquad_balance)
- return [house for house, flag in zip(HypeSquadHouse, flags) if self._has_flag(flag)]
-
- @property
- def team_user(self):
- return self._has_flag(UserFlags.team_user)
-
- @property
- def system(self):
- return self._has_flag(UserFlags.system)
_BaseUser = discord.abc.User
@@ -314,32 +264,16 @@ class ClientUser(BaseUser):
verified: :class:`bool`
Specifies if the user is a verified account.
- email: Optional[:class:`str`]
- The email the user used when registering.
-
- .. deprecated:: 1.7
-
locale: Optional[:class:`str`]
The IETF language tag used to identify the language the user is using.
mfa_enabled: :class:`bool`
Specifies if the user has MFA turned on and working.
- premium: :class:`bool`
- Specifies if the user is a premium user (e.g. has Discord Nitro).
-
- .. deprecated:: 1.7
-
- premium_type: Optional[:class:`PremiumType`]
- Specifies the type of premium a user has (e.g. Nitro or Nitro Classic). Could be None if the user is not premium.
-
- .. deprecated:: 1.7
"""
__slots__ = BaseUser.__slots__ + \
- ('email', 'locale', '_flags', 'verified', 'mfa_enabled',
- 'premium', 'premium_type', '_relationships', '__weakref__')
+ ('locale', '_flags', 'verified', 'mfa_enabled', '__weakref__')
def __init__(self, *, state, data):
super().__init__(state=state, data=data)
- self._relationships = {}
def __repr__(self):
return '<ClientUser id={0.id} name={0.name!r} discriminator={0.discriminator!r}' \
@@ -349,83 +283,16 @@ class ClientUser(BaseUser):
super()._update(data)
# There's actually an Optional[str] phone field as well but I won't use it
self.verified = data.get('verified', False)
- self.email = data.get('email')
self.locale = data.get('locale')
self._flags = data.get('flags', 0)
self.mfa_enabled = data.get('mfa_enabled', False)
- self.premium = data.get('premium', False)
- self.premium_type = try_enum(PremiumType, data.get('premium_type', None))
-
- @deprecated()
- def get_relationship(self, user_id):
- """Retrieves the :class:`Relationship` if applicable.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Parameters
- -----------
- user_id: :class:`int`
- The user ID to check if we have a relationship with them.
-
- Returns
- --------
- Optional[:class:`Relationship`]
- The relationship if available or ``None``.
- """
- return self._relationships.get(user_id)
-
- @property
- def relationships(self):
- """List[:class:`User`]: Returns all the relationships that the user has.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
- """
- return list(self._relationships.values())
-
- @property
- def friends(self):
- r"""List[:class:`User`]: Returns all the users that the user is friends with.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
- """
- return [r.user for r in self._relationships.values() if r.type is RelationshipType.friend]
-
- @property
- def blocked(self):
- r"""List[:class:`User`]: Returns all the users that the user has blocked.
-
- .. deprecated:: 1.7
- .. note::
- This can only be used by non-bot accounts.
- """
- return [r.user for r in self._relationships.values() if r.type is RelationshipType.blocked]
-
- async def edit(self, **fields):
+ async def edit(self, *, username=None, avatar=None):
"""|coro|
Edits the current profile of the client.
- If a bot account is used then a password field is optional,
- otherwise it is required.
-
- .. warning::
-
- The user account-only fields are deprecated.
-
.. note::
To upload an avatar, a :term:`py:bytes-like object` must be passed in that
@@ -437,19 +304,6 @@ class ClientUser(BaseUser):
Parameters
-----------
- password: :class:`str`
- The current password for the client's account.
- Only applicable to user accounts.
- new_password: :class:`str`
- The new password you wish to change to.
- Only applicable to user accounts.
- email: :class:`str`
- The new email you wish to change to.
- Only applicable to user accounts.
- house: Optional[:class:`HypeSquadHouse`]
- The hypesquad house you wish to change to.
- Could be ``None`` to leave the current house.
- Only applicable to user accounts.
username: :class:`str`
The new username you wish to change to.
avatar: :class:`bytes`
@@ -462,218 +316,14 @@ class ClientUser(BaseUser):
Editing your profile failed.
InvalidArgument
Wrong image format passed for ``avatar``.
- ClientException
- Password is required for non-bot accounts.
- House field was not a HypeSquadHouse.
"""
- try:
- avatar_bytes = fields['avatar']
- except KeyError:
- avatar = self.avatar
- else:
- if avatar_bytes is not None:
- avatar = _bytes_to_base64_data(avatar_bytes)
- else:
- avatar = None
-
- not_bot_account = not self.bot
- password = fields.get('password')
- if not_bot_account and password is None:
- raise ClientException('Password is required for non-bot accounts.')
-
- args = {
- 'password': password,
- 'username': fields.get('username', self.name),
- 'avatar': avatar
- }
-
- if not_bot_account:
- args['email'] = fields.get('email', self.email)
-
- if 'new_password' in fields:
- args['new_password'] = fields['new_password']
-
- http = self._state.http
-
- if 'house' in fields:
- house = fields['house']
- if house is None:
- await http.leave_hypesquad_house()
- elif not isinstance(house, HypeSquadHouse):
- raise ClientException('`house` parameter was not a HypeSquadHouse')
- else:
- value = house.value
-
- await http.change_hypesquad_house(value)
-
- data = await http.edit_profile(**args)
- if not_bot_account:
- self.email = data['email']
- try:
- http._token(data['token'], bot=False)
- except KeyError:
- pass
+ if avatar is not None:
+ avatar = _bytes_to_base64_data(avatar)
+ data = await self._state.http.edit_profile(username=username, avatar=avatar)
self._update(data)
- @deprecated()
- async def create_group(self, *recipients):
- r"""|coro|
-
- Creates a group direct message with the recipients
- provided. These recipients must be have a relationship
- of type :attr:`RelationshipType.friend`.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Parameters
- -----------
- \*recipients: :class:`User`
- An argument :class:`list` of :class:`User` to have in
- your group.
-
- Raises
- -------
- HTTPException
- Failed to create the group direct message.
- ClientException
- Attempted to create a group with only one recipient.
- This does not include yourself.
-
- Returns
- -------
- :class:`GroupChannel`
- The new group channel.
- """
-
- from .channel import GroupChannel
-
- if len(recipients) < 2:
- raise ClientException('You must have two or more recipients to create a group.')
-
- users = [str(u.id) for u in recipients]
- data = await self._state.http.start_group(self.id, users)
- return GroupChannel(me=self, data=data, state=self._state)
-
- @deprecated()
- async def edit_settings(self, **kwargs):
- """|coro|
-
- Edits the client user's settings.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Parameters
- -------
- afk_timeout: :class:`int`
- How long (in seconds) the user needs to be AFK until Discord
- sends push notifications to your mobile device.
- animate_emojis: :class:`bool`
- Whether or not to animate emojis in the chat.
- convert_emoticons: :class:`bool`
- Whether or not to automatically convert emoticons into emojis.
- e.g. :-) -> 😃
- default_guilds_restricted: :class:`bool`
- Whether or not to automatically disable DMs between you and
- members of new guilds you join.
- detect_platform_accounts: :class:`bool`
- Whether or not to automatically detect accounts from services
- like Steam and Blizzard when you open the Discord client.
- developer_mode: :class:`bool`
- Whether or not to enable developer mode.
- disable_games_tab: :class:`bool`
- Whether or not to disable the showing of the Games tab.
- enable_tts_command: :class:`bool`
- Whether or not to allow tts messages to be played/sent.
- explicit_content_filter: :class:`UserContentFilter`
- The filter for explicit content in all messages.
- friend_source_flags: :class:`FriendFlags`
- Who can add you as a friend.
- gif_auto_play: :class:`bool`
- Whether or not to automatically play gifs that are in the chat.
- guild_positions: List[:class:`abc.Snowflake`]
- A list of guilds in order of the guild/guild icons that are on
- the left hand side of the UI.
- inline_attachment_media: :class:`bool`
- Whether or not to display attachments when they are uploaded in chat.
- inline_embed_media: :class:`bool`
- Whether or not to display videos and images from links posted in chat.
- locale: :class:`str`
- The :rfc:`3066` language identifier of the locale to use for the language
- of the Discord client.
- message_display_compact: :class:`bool`
- Whether or not to use the compact Discord display mode.
- render_embeds: :class:`bool`
- Whether or not to render embeds that are sent in the chat.
- render_reactions: :class:`bool`
- Whether or not to render reactions that are added to messages.
- restricted_guilds: List[:class:`abc.Snowflake`]
- A list of guilds that you will not receive DMs from.
- show_current_game: :class:`bool`
- Whether or not to display the game that you are currently playing.
- status: :class:`Status`
- The clients status that is shown to others.
- theme: :class:`Theme`
- The theme of the Discord UI.
- timezone_offset: :class:`int`
- The timezone offset to use.
-
- Raises
- -------
- HTTPException
- Editing the settings failed.
- Forbidden
- The client is a bot user and not a user account.
-
- Returns
- -------
- :class:`dict`
- The client user's updated settings.
- """
- payload = {}
-
- content_filter = kwargs.pop('explicit_content_filter', None)
- if content_filter:
- payload.update({'explicit_content_filter': content_filter.value})
-
- friend_flags = kwargs.pop('friend_source_flags', None)
- if friend_flags:
- dicts = [{}, {'mutual_guilds': True}, {'mutual_friends': True},
- {'mutual_guilds': True, 'mutual_friends': True}, {'all': True}]
- payload.update({'friend_source_flags': dicts[friend_flags.value]})
-
- guild_positions = kwargs.pop('guild_positions', None)
- if guild_positions:
- guild_positions = [str(x.id) for x in guild_positions]
- payload.update({'guild_positions': guild_positions})
-
- restricted_guilds = kwargs.pop('restricted_guilds', None)
- if restricted_guilds:
- restricted_guilds = [str(x.id) for x in restricted_guilds]
- payload.update({'restricted_guilds': restricted_guilds})
-
- status = kwargs.pop('status', None)
- if status:
- payload.update({'status': status.value})
-
- theme = kwargs.pop('theme', None)
- if theme:
- payload.update({'theme': theme.value})
-
- payload.update(kwargs)
-
- data = await self._state.http.edit_settings(**payload)
- return data
-
class User(BaseUser, discord.abc.Messageable):
"""Represents a Discord user.
@@ -761,197 +411,3 @@ class User(BaseUser, discord.abc.Messageable):
state = self._state
data = await state.http.start_private_message(self.id)
return state.add_dm_channel(data)
-
- @property
- def relationship(self):
- """Optional[:class:`Relationship`]: Returns the :class:`Relationship` with this user if applicable, ``None`` otherwise.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
- """
- return self._state.user.get_relationship(self.id)
-
- @deprecated()
- async def mutual_friends(self):
- """|coro|
-
- Gets all mutual friends of this user.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to get mutual friends of this user.
- HTTPException
- Getting mutual friends failed.
-
- Returns
- -------
- List[:class:`User`]
- The users that are mutual friends.
- """
- state = self._state
- mutuals = await state.http.get_mutual_friends(self.id)
- return [User(state=state, data=friend) for friend in mutuals]
-
- @deprecated()
- def is_friend(self):
- """:class:`bool`: Checks if the user is your friend.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
- """
- r = self.relationship
- if r is None:
- return False
- return r.type is RelationshipType.friend
-
- @deprecated()
- def is_blocked(self):
- """:class:`bool`: Checks if the user is blocked.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
- """
- r = self.relationship
- if r is None:
- return False
- return r.type is RelationshipType.blocked
-
- @deprecated()
- async def block(self):
- """|coro|
-
- Blocks the user.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to block this user.
- HTTPException
- Blocking the user failed.
- """
-
- await self._state.http.add_relationship(self.id, type=RelationshipType.blocked.value)
-
- @deprecated()
- async def unblock(self):
- """|coro|
-
- Unblocks the user.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to unblock this user.
- HTTPException
- Unblocking the user failed.
- """
- await self._state.http.remove_relationship(self.id)
-
- @deprecated()
- async def remove_friend(self):
- """|coro|
-
- Removes the user as a friend.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to remove this user as a friend.
- HTTPException
- Removing the user as a friend failed.
- """
- await self._state.http.remove_relationship(self.id)
-
- @deprecated()
- async def send_friend_request(self):
- """|coro|
-
- Sends the user a friend request.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to send a friend request to the user.
- HTTPException
- Sending the friend request failed.
- """
- await self._state.http.send_friend_request(username=self.name, discriminator=self.discriminator)
-
- @deprecated()
- async def profile(self):
- """|coro|
-
- Gets the user's profile.
-
- .. deprecated:: 1.7
-
- .. note::
-
- This can only be used by non-bot accounts.
-
- Raises
- -------
- Forbidden
- Not allowed to fetch profiles.
- HTTPException
- Fetching the profile failed.
-
- Returns
- --------
- :class:`Profile`
- The profile of the user.
- """
-
- state = self._state
- data = await state.http.get_user_profile(self.id)
-
- def transform(d):
- return state._get_guild(int(d['id']))
-
- since = data.get('premium_since')
- mutual_guilds = list(filter(None, map(transform, data.get('mutual_guilds', []))))
- return Profile(flags=data['user'].get('flags', 0),
- premium_since=parse_time(since),
- mutual_guilds=mutual_guilds,
- user=self,
- connected_accounts=data['connected_accounts'])