Browse Source

Add application-related methods, fix a couple typos

pull/10109/head
dolfies 3 years ago
parent
commit
bfec72eb58
  1. 124
      discord/client.py
  2. 4
      discord/http.py
  3. 25
      discord/team.py

124
discord/client.py

@ -54,7 +54,7 @@ from .utils import MISSING
from .object import Object from .object import Object
from .backoff import ExponentialBackoff from .backoff import ExponentialBackoff
from .webhook import Webhook from .webhook import Webhook
from .appinfo import Application from .appinfo import Application, PartialApplication
from .stage_instance import StageInstance from .stage_instance import StageInstance
from .threads import Thread from .threads import Thread
from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory
@ -2007,10 +2007,10 @@ class Client:
... ...
@overload @overload
async def send_friend_request(self, username: str, discriminator: Union[int, str]) -> Relationship: async def send_friend_request(self, username: str, discriminator: str) -> Relationship:
... ...
async def send_friend_request(self, *args: Union[BaseUser, int, str]) -> Relationship: async def send_friend_request(self, *args: Union[BaseUser, str]) -> Relationship:
"""|coro| """|coro|
Sends a friend request to another user. Sends a friend request to another user.
@ -2052,7 +2052,7 @@ class Client:
The new relationship. The new relationship.
""" """
username: str username: str
discrim: Union[str, int] discrim: str
if len(args) == 1: if len(args) == 1:
user = args[0] user = args[0]
if isinstance(user, BaseUser): if isinstance(user, BaseUser):
@ -2067,6 +2067,122 @@ class Client:
data = await state.http.send_friend_request(username, discrim) data = await state.http.send_friend_request(username, discrim)
return Relationship(state=state, data=data) return Relationship(state=state, data=data)
async def applications(self, *, with_team_applications: bool = True) -> List[Application]:
"""|coro|
Retrieves all applications owned by you.
.. versionadded:: 2.0
Parameters
-----------
with_team_applications: :class:`bool`
Whether to include applications owned by teams you're a part of.
Defaults to ``True``.
Raises
-------
:exc:`.HTTPException`
Retrieving the applications failed.
Returns
-------
List[:class:`.Application`]
The applications you own.
"""
state = self._connection
data = await state.http.get_my_applications(with_team_applications=with_team_applications)
return [Application(state=state, data=d) for d in data]
async def fetch_application(self, app_id: int, /) -> Application:
"""|coro|
Retrieves the application with the given ID.
The application must be owned by you.
.. versionadded:: 2.0
Parameters
-----------
id: :class:`int`
The ID of the application to fetch.
Raises
-------
:exc:`.HTTPException`
Retrieving the application failed.
Returns
-------
:class:`.Application`
The retrieved application.
"""
state = self._connection
data = await state.http.get_my_application(app_id)
return Application(state=state, data=data)
async def fetch_partial_application(self, app_id: int, /) -> PartialApplication:
"""|coro|
Retrieves the partial application with the given ID.
Returns
--------
:class:`.PartialApplication`
The retrieved application.
"""
state = self._connection
data = await state.http.get_partial_application(app_id)
return PartialApplication(state=state, data=data)
async def teams(self) -> List[Team]:
"""|coro|
Retrieves all the teams you're a part of.
.. versionadded:: 2.0
Raises
-------
:exc:`.HTTPException`
Retrieving the teams failed.
Returns
-------
List[:class:`.Team`]
The teams you're a part of.
"""
state = self._connection
data = await state.http.get_teams()
return [Team(state=state, data=d) for d in data]
async def fetch_team(self, team_id: int, /) -> Team:
"""|coro|
Retrieves the team with the given ID.
.. versionadded:: 2.0
Parameters
-----------
id: :class:`int`
The ID of the team to fetch.
Raises
-------
:exc:`.HTTPException`
Retrieving the team failed.
Returns
-------
:class:`.Team`
The retrieved team.
"""
state = self._connection
data = await state.http.get_team(team_id)
return Team(state=state, data=data)
async def create_application(self, name: str): async def create_application(self, name: str):
"""|coro| """|coro|

4
discord/http.py

@ -1881,7 +1881,7 @@ class HTTPClient:
return self.request(Route('POST', '/applications/{app_id}/transfer', app_id=app_id), json=payload, super_properties_to_track=True) return self.request(Route('POST', '/applications/{app_id}/transfer', app_id=app_id), json=payload, super_properties_to_track=True)
def get_partial_application(self, app_id: Snowflake) -> Response[appinfo.PartialAppInfo]: def get_partial_application(self, app_id: Snowflake) -> Response[appinfo.PartialAppInfo]:
return self.request(Route('GET', '/applications/{app_id}/rpc', app_id=app_id), auth=False) return self.request(Route('GET', '/applications/{app_id}/rpc', app_id=app_id))
def create_app(self, name: str): def create_app(self, name: str):
payload = { payload = {
@ -1924,7 +1924,7 @@ class HTTPClient:
def edit_team(self, team_id: Snowflake, payload) -> Response[team.Team]: def edit_team(self, team_id: Snowflake, payload) -> Response[team.Team]:
return self.request(Route('PATCH', '/teams/{team_id}', team_id=team_id), json=payload, super_properties_to_track=True) return self.request(Route('PATCH', '/teams/{team_id}', team_id=team_id), json=payload, super_properties_to_track=True)
def delete_application(self, team_id: Snowflake) -> Response[None]: def delete_team(self, team_id: Snowflake) -> Response[None]:
return self.request(Route('POST', '/teams/{app_id}/delete', team_id=team_id), super_properties_to_track=True) return self.request(Route('POST', '/teams/{app_id}/delete', team_id=team_id), super_properties_to_track=True)
def get_team_applications(self, team_id: Snowflake) -> Response[List[appinfo.AppInfo]]: def get_team_applications(self, team_id: Snowflake) -> Response[List[appinfo.AppInfo]]:

25
discord/team.py

@ -143,10 +143,9 @@ class Team:
payload['icon'] = '' payload['icon'] = ''
if owner is not MISSING: if owner is not MISSING:
payload['owner_user_id'] = owner.id payload['owner_user_id'] = owner.id
await self._state.http.edit_team(self.id, payload)
await self._state.http.edit_team(self.id, payload) data = await self._state.http.edit_team(self.id, payload)
self._update(payload) self._update(data)
async def fetch_members(self) -> List[TeamMember]: async def fetch_members(self) -> List[TeamMember]:
"""|coro| """|coro|
@ -179,10 +178,10 @@ class Team:
... ...
@overload @overload
async def invite_member(self, username: str, discriminator: Union[int, str]) -> TeamMember: async def invite_member(self, username: str, discriminator: str) -> TeamMember:
... ...
async def invite_member(self, *args: Union[BaseUser, int, str]) -> TeamMember: async def invite_member(self, *args: Union[BaseUser, str]) -> TeamMember:
"""|coro| """|coro|
Invites a member to the team. Invites a member to the team.
@ -224,7 +223,7 @@ class Team:
The new member. The new member.
""" """
username: str username: str
discrim: Union[str, int] discrim: str
if len(args) == 1: if len(args) == 1:
user = args[0] user = args[0]
if isinstance(user, BaseUser): if isinstance(user, BaseUser):
@ -241,6 +240,20 @@ class Team:
self.members.append(member) self.members.append(member)
return member return member
async def delete(self) -> None:
"""|coro|
Deletes the team.
Raises
-------
Forbidden
You do not have permissions to delete the team.
HTTPException
Deleting the team failed.
"""
await self._state.http.delete_team(self.id)
class TeamMember(BaseUser): class TeamMember(BaseUser):
"""Represents a team member in a team. """Represents a team member in a team.

Loading…
Cancel
Save