Browse Source

Make more methods positional-only and privatize fetch_sticker_packs() parameters

pull/10109/head
dolfies 3 years ago
parent
commit
8344783a11
  1. 59
      discord/client.py

59
discord/client.py

@ -714,9 +714,9 @@ class Client:
try: try:
asyncio.run(runner()) asyncio.run(runner())
except KeyboardInterrupt: except KeyboardInterrupt:
# nothing to do here # Nothing to do here
# `asyncio.run` handles the loop cleanup # `asyncio.run` handles the loop cleanup
# and `self.start` closes all sockets and the HTTPClient instance. # and `self.start` closes all sockets and the HTTPClient instance
return return
# Properties # Properties
@ -1371,7 +1371,10 @@ class Client:
if getattr(activity, 'type', None) is ActivityType.custom: if getattr(activity, 'type', None) is ActivityType.custom:
custom_activity = activity custom_activity = activity
payload: Dict[str, Any] = {'status': status} payload: Dict[str, Any] = {}
if status != getattr(self.user.settings, 'status', None): # type: ignore - user is always present when logged in
payload['status'] = status
if custom_activity != getattr(self.user.settings, 'custom_activity', None): # type: ignore - user is always present when logged in
payload['custom_activity'] = custom_activity payload['custom_activity'] = custom_activity
await self.user.edit_settings(**payload) # type: ignore - user is always present when logged in await self.user.edit_settings(**payload) # type: ignore - user is always present when logged in
@ -1494,6 +1497,10 @@ class Client:
Retrieves a :class:`.Guild` from an ID. Retrieves a :class:`.Guild` from an ID.
.. versionchanged:: 2.0
``guild_id`` parameter is now positional-only.
.. note:: .. note::
Using this, you will **not** receive :attr:`.Guild.channels` and :attr:`.Guild.members`. Using this, you will **not** receive :attr:`.Guild.channels` and :attr:`.Guild.members`.
@ -1539,6 +1546,8 @@ class Client:
Retrieves a public :class:`.Guild` preview from an ID. Retrieves a public :class:`.Guild` preview from an ID.
.. versionadded:: 2.0
Raises Raises
------ ------
NotFound NotFound
@ -1703,6 +1712,7 @@ class Client:
async def fetch_invite( async def fetch_invite(
self, self,
url: Union[Invite, str], url: Union[Invite, str],
/,
*, *,
with_counts: bool = True, with_counts: bool = True,
with_expiration: bool = True, with_expiration: bool = True,
@ -1718,6 +1728,10 @@ class Client:
attributes of the returned :class:`.Invite` will be :class:`.PartialInviteGuild` and attributes of the returned :class:`.Invite` will be :class:`.PartialInviteGuild` and
:class:`.PartialInviteChannel` respectively. :class:`.PartialInviteChannel` respectively.
.. versionchanged:: 2.0
``url`` parameter is now positional-only.
Parameters Parameters
----------- -----------
url: Union[:class:`.Invite`, :class:`str`] url: Union[:class:`.Invite`, :class:`str`]
@ -1800,7 +1814,7 @@ class Client:
resolved = utils.resolve_invite(invite) resolved = utils.resolve_invite(invite)
await self.http.delete_invite(resolved.code) await self.http.delete_invite(resolved.code)
async def accept_invite(self, invite: Union[Invite, str]) -> Union[Guild, User, GroupChannel]: async def accept_invite(self, invite: Union[Invite, str], /) -> Union[Guild, User, GroupChannel]:
"""|coro| """|coro|
Uses an invite. Uses an invite.
@ -1808,6 +1822,10 @@ class Client:
.. versionadded:: 1.9 .. versionadded:: 1.9
.. versionchanged:: 2.0
``invite`` parameter is now positional-only.
Parameters Parameters
---------- ----------
invite: Union[:class:`.Invite`, :class:`str`] invite: Union[:class:`.Invite`, :class:`str`]
@ -2073,26 +2091,13 @@ class Client:
cls, _ = _sticker_factory(data['type']) cls, _ = _sticker_factory(data['type'])
return cls(state=self._connection, data=data) # type: ignore return cls(state=self._connection, data=data) # type: ignore
async def fetch_sticker_packs( async def fetch_sticker_packs(self) -> List[StickerPack]:
self, *, country: str = 'US', locale: str = 'en-US', payment_source_id: int = MISSING
) -> List[StickerPack]:
"""|coro| """|coro|
Retrieves all available default sticker packs. Retrieves all available default sticker packs.
.. versionadded:: 2.0 .. versionadded:: 2.0
Parameters
-----------
country: :class:`str`
ISO 3166 country code to fetch the sticker packs for.
Defaults to ``US``.
locale: :class:`str`
ISO 639 language code the name and description should be in.
Defaults to ``en-US``.
payment_source_id: :class:`int`
Unknown.
Raises Raises
------- -------
HTTPException HTTPException
@ -2103,7 +2108,7 @@ class Client:
List[:class:`.StickerPack`] List[:class:`.StickerPack`]
All available sticker packs. All available sticker packs.
""" """
data = await self.http.list_premium_sticker_packs(country, locale, payment_source_id) data = await self.http.list_premium_sticker_packs()
return [StickerPack(state=self._connection, data=pack) for pack in data['sticker_packs']] return [StickerPack(state=self._connection, data=pack) for pack in data['sticker_packs']]
async def fetch_sticker_pack(self, pack_id: int, /): async def fetch_sticker_pack(self, pack_id: int, /):
@ -2149,13 +2154,17 @@ class Client:
data = await state.http.get_notes() data = await state.http.get_notes()
return [Note(state, int(id), note=note) for id, note in data.items()] return [Note(state, int(id), note=note) for id, note in data.items()]
async def fetch_note(self, user_id: int) -> Note: async def fetch_note(self, user_id: int, /) -> Note:
"""|coro| """|coro|
Retrieves a :class:`Note` for the specified user ID. Retrieves a :class:`Note` for the specified user ID.
.. versionadded:: 1.9 .. versionadded:: 1.9
.. versionchanged:: 2.0
``user_id`` parameter is now positional-only.
Parameters Parameters
----------- -----------
user_id: :class:`int` user_id: :class:`int`
@ -2217,7 +2226,7 @@ class Client:
channels = await state.http.get_private_channels() channels = await state.http.get_private_channels()
return [_private_channel_factory(data['type'])[0](me=self.user, data=data, state=state) for data in channels] # type: ignore - user is always present when logged in return [_private_channel_factory(data['type'])[0](me=self.user, data=data, state=state) for data in channels] # type: ignore - user is always present when logged in
async def create_dm(self, user: Snowflake) -> DMChannel: async def create_dm(self, user: Snowflake, /) -> DMChannel:
"""|coro| """|coro|
Creates a :class:`.DMChannel` with this user. Creates a :class:`.DMChannel` with this user.
@ -2294,6 +2303,10 @@ class Client:
This function can be used in multiple ways. This function can be used in multiple ways.
.. versionchanged:: 2.0
All parameters are now positional-only.
.. code-block:: python .. code-block:: python
# Passing a user object: # Passing a user object:
@ -2484,7 +2497,7 @@ class Client:
data = await state.http.get_team(team_id) data = await state.http.get_team(team_id)
return Team(state=state, data=data) return Team(state=state, data=data)
async def create_application(self, name: str): async def create_application(self, name: str, /):
"""|coro| """|coro|
Creates an application. Creates an application.
@ -2510,7 +2523,7 @@ class Client:
data = await state.http.create_app(name) data = await state.http.create_app(name)
return Application(state=state, data=data) return Application(state=state, data=data)
async def create_team(self, name: str): async def create_team(self, name: str, /):
"""|coro| """|coro|
Creates a team. Creates a team.

Loading…
Cancel
Save