From f500fd6d89e9d6e92d906ce0acea0be1d3bcc42a Mon Sep 17 00:00:00 2001 From: dolfies Date: Thu, 20 May 2021 17:55:13 -0400 Subject: [PATCH 1/2] Re-add deprecated user-only functions and remove bot-only functions. --- discord/abc.py | 31 ----------- discord/channel.py | 70 ++---------------------- discord/client.py | 46 ---------------- discord/http.py | 2 +- discord/user.py | 132 +++------------------------------------------ 5 files changed, 13 insertions(+), 268 deletions(-) diff --git a/discord/abc.py b/discord/abc.py index 0e48a2f4e2af..86c9a5fb2be1 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1101,37 +1101,6 @@ def typing(self): """ return Typing(self) - async def fetch_message(self, id): - """|coro| - - Retrieves a single :class:`~discord.Message` from the destination. - - This can only be used by bot accounts. - - Parameters - ------------ - id: :class:`int` - The message ID to look for. - - Raises - -------- - ~discord.NotFound - The specified message was not found. - ~discord.Forbidden - You do not have the permissions required to get a message. - ~discord.HTTPException - Retrieving the message failed. - - Returns - -------- - :class:`~discord.Message` - The message asked for. - """ - - channel = await self._get_channel() - data = await self._state.http.get_message(channel.id, id) - return self._state.create_message(channel=channel, data=data) - async def pins(self): """|coro| diff --git a/discord/channel.py b/discord/channel.py index f90491c601c3..6fe047542a2a 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -174,9 +174,8 @@ def last_message(self): :class: helpful For a slightly more reliable method of fetching the - last message, consider using either :meth:`history` - or :meth:`fetch_message` with the :attr:`last_message_id` - attribute. + last message, consider using :meth:`history` + with the :attr:`last_message_id` attribute. Returns --------- @@ -248,59 +247,7 @@ async def clone(self, *, name=None, reason=None): 'rate_limit_per_user': self.slowmode_delay }, name=name, reason=reason) - async def delete_messages(self, messages): - """|coro| - - Deletes a list of messages. This is similar to :meth:`Message.delete` - except it bulk deletes multiple messages. - - As a special case, if the number of messages is 0, then nothing - is done. If the number of messages is 1 then single message - delete is done. If it's more than two, then bulk delete is used. - - You cannot bulk delete more than 100 messages or messages that - are older than 14 days old. - - You must have the :attr:`~Permissions.manage_messages` permission to - use this. - - Usable only by bot accounts. - - Parameters - ----------- - messages: Iterable[:class:`abc.Snowflake`] - An iterable of messages denoting which ones to bulk delete. - - Raises - ------ - ClientException - The number of messages to delete was more than 100. - Forbidden - You do not have proper permissions to delete the messages or - you're not using a bot account. - NotFound - If single delete, then the message was already deleted. - HTTPException - Deleting the messages failed. - """ - if not isinstance(messages, (list, tuple)): - messages = list(messages) - - if len(messages) == 0: - return # do nothing - - if len(messages) == 1: - message_id = messages[0].id - await self._state.http.delete_message(self.id, message_id) - return - - if len(messages) > 100: - raise ClientException('Can only bulk delete messages up to 100 messages') - - message_ids = [m.id for m in messages] - await self._state.http.delete_messages(self.id, message_ids) - - async def purge(self, *, limit=100, check=None, before=None, after=None, around=None, oldest_first=False, bulk=True): + async def purge(self, *, limit=100, check=None, before=None, after=None, around=None, oldest_first=False): """|coro| Purges a list of messages that meet the criteria given by the predicate @@ -312,10 +259,6 @@ async def purge(self, *, limit=100, check=None, before=None, after=None, around= account). The :attr:`~Permissions.read_message_history` permission is also needed to retrieve message history. - Internally, this employs a different number of strategies depending - on the conditions met such as if a bulk delete is possible or if - the account is a user bot or not. - Examples --------- @@ -343,11 +286,6 @@ def is_me(m): Same as ``around`` in :meth:`history`. oldest_first: Optional[:class:`bool`] Same as ``oldest_first`` in :meth:`history`. - bulk: :class:`bool` - If ``True``, use bulk delete. Setting this to ``False`` is useful for mass-deleting - a bot's own messages without :attr:`Permissions.manage_messages`. When ``True``, will - fall back to single delete if current account is a user bot (now deprecated), or if messages are - older than two weeks. Raises ------- @@ -370,7 +308,7 @@ def is_me(m): count = 0 minimum_time = int((time.time() - 14 * 24 * 60 * 60) * 1000.0 - 1420070400000) << 22 - strategy = self.delete_messages if self._state.is_bot and bulk else _single_delete_strategy + strategy = _single_delete_strategy while True: try: diff --git a/discord/client.py b/discord/client.py index 93bcfe7829f5..973ba64ee737 100644 --- a/discord/client.py +++ b/discord/client.py @@ -491,11 +491,6 @@ async def login(self, token): token: :class:`str` The authentication token. Do not prefix this token with anything as the library will do it for you. - bot: :class:`bool` - Keyword argument that specifies if the account logging on is a bot - token or not. - - .. deprecated:: 1.7 Raises ------ @@ -1192,8 +1187,6 @@ async def create_guild(self, name, region=None, icon=None, *, code=None): Creates a :class:`.Guild`. - Bot accounts in more than 10 guilds are not allowed to create guilds. - Parameters ---------- name: :class:`str` @@ -1351,50 +1344,11 @@ async def application_info(self): data['rpc_origins'] = None return AppInfo(self._connection, data) - async def fetch_user(self, user_id): - """|coro| - - Retrieves a :class:`~discord.User` based on their ID. This can only - be used by bot accounts. You do not have to share any guilds - with the user to get this information, however many operations - do require that you do. - - .. note:: - - This method is an API call. If you have :attr:`Intents.members` and member cache enabled, consider :meth:`get_user` instead. - - Parameters - ----------- - user_id: :class:`int` - The user's ID to fetch from. - - Raises - ------- - :exc:`.NotFound` - A user with this ID does not exist. - :exc:`.HTTPException` - Fetching the user failed. - - Returns - -------- - :class:`~discord.User` - The user you requested. - """ - data = await self.http.get_user(user_id) - return User(state=self._connection, data=data) - - @utils.deprecated() async def fetch_user_profile(self, user_id): """|coro| Gets an arbitrary user's profile. - .. deprecated:: 1.7 - - .. note:: - - This can only be used by non-bot accounts. - Parameters ------------ user_id: :class:`int` diff --git a/discord/http.py b/discord/http.py index 6e5b24b2ebed..e12a826443db 100644 --- a/discord/http.py +++ b/discord/http.py @@ -148,7 +148,7 @@ async def request(self, route, *, files=None, form=None, **kwargs): } if self.token is not None: - headers['Authorization'] = 'Bot ' + self.token if self.bot_token else self.token + headers['Authorization'] = self.token # some checking if it's a JSON request if 'json' in kwargs: headers['Content-Type'] = 'application/json' diff --git a/discord/user.py b/discord/user.py index 4a7d9ba5b8da..7d9a7b51a653 100644 --- a/discord/user.py +++ b/discord/user.py @@ -319,8 +319,6 @@ class ClientUser(BaseUser): 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` @@ -358,16 +356,9 @@ def _update(self, data): 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` @@ -382,38 +373,17 @@ def get_relationship(self, 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. - """ + """List[:class:`User`]: Returns all the relationships that the user has.""" 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. - """ + r"""List[:class:`User`]: Returns all the users that the user is friends with.""" 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. - """ + r"""List[:class:`User`]: Returns all the users that the user has blocked.""" return [r.user for r in self._relationships.values() if r.type is RelationshipType.blocked] async def edit(self, **fields): @@ -421,13 +391,6 @@ async def edit(self, **fields): 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 @@ -465,7 +428,7 @@ async def edit(self, **fields): InvalidArgument Wrong image format passed for ``avatar``. ClientException - Password is required for non-bot accounts. + Password was not passed. House field was not a HypeSquadHouse. """ @@ -482,7 +445,7 @@ async def edit(self, **fields): 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.') + raise ClientException('Password is required') args = { 'password': password, @@ -519,7 +482,6 @@ async def edit(self, **fields): self._update(data) - @deprecated() async def create_group(self, *recipients): r"""|coro| @@ -527,12 +489,6 @@ async def create_group(self, *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` @@ -562,18 +518,11 @@ async def create_group(self, *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` @@ -766,28 +715,14 @@ async def create_dm(self): @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. - """ + """Optional[:class:`Relationship`]: Returns the :class:`Relationship` with this user if applicable, ``None`` otherwise.""" 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 @@ -804,48 +739,25 @@ async def mutual_friends(self): 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. - """ + """:class:`bool`: Checks if the user is your friend.""" 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. - """ + """:class:`bool`: Checks if the user is blocked.""" 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 @@ -856,18 +768,11 @@ async def block(self): 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 @@ -877,18 +782,11 @@ async def unblock(self): """ 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 @@ -898,18 +796,11 @@ async def remove_friend(self): """ 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 @@ -919,18 +810,11 @@ async def send_friend_request(self): """ 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 From a01e72a3069d0905cabf2d65c37ce60bb19ee217 Mon Sep 17 00:00:00 2001 From: dolfies Date: Thu, 20 May 2021 17:58:53 -0400 Subject: [PATCH 2/2] Re-add deprecated user-only functions and remove bot-only functions. --- discord/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/__init__.py b/discord/__init__.py index 08553418e168..e09c8a03186e 100644 --- a/discord/__init__.py +++ b/discord/__init__.py @@ -15,7 +15,7 @@ __author__ = 'Rapptz' __license__ = 'MIT' __copyright__ = 'Copyright 2015-present Rapptz' -__version__ = '1.7.7' +__version__ = '1.7.8' __path__ = __import__('pkgutil').extend_path(__path__, __name__) @@ -62,6 +62,6 @@ VersionInfo = namedtuple('VersionInfo', 'major minor micro releaselevel serial') -version_info = VersionInfo(major=1, minor=7, micro=7, releaselevel='final', serial=0) +version_info = VersionInfo(major=1, minor=7, micro=8, releaselevel='final', serial=0) logging.getLogger(__name__).addHandler(logging.NullHandler())