Skip to content

Commit

Permalink
feat: Add support for new team roles
Browse files Browse the repository at this point in the history
  • Loading branch information
mccoderpy committed Aug 25, 2023
1 parent 0758b5a commit 288173e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
8 changes: 8 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'PremiumType',
'FriendFlags',
'TeamMembershipState',
'TeamRole',
'TextInputStyle',
'Theme',
'WebhookType',
Expand Down Expand Up @@ -1035,6 +1036,13 @@ class TeamMembershipState(Enum):
accepted = 2


class TeamRole(Enum):
owner = 'owner'
admin = 'admin'
developer = 'developer'
read_only = 'read_only'


class WebhookType(Enum):
incoming = 1
channel_follower = 2
Expand Down
23 changes: 17 additions & 6 deletions discord/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from . import utils
from .user import BaseUser
from .asset import Asset
from .enums import TeamMembershipState, try_enum
from .enums import TeamMembershipState, TeamRole, try_enum

__all__ = (
'Team',
Expand Down Expand Up @@ -175,18 +175,29 @@ class TeamMember(BaseUser):
The team that the member is from.
membership_state: :class:`TeamMembershipState`
The membership state of the member (e.g. invited or accepted)
role: :class:`TeamRole`
The role of the team member.
.. versionadded:: 2.0
"""
__slots__ = BaseUser.__slots__ + ('team', 'membership_state', 'permissions')
__slots__ = BaseUser.__slots__ + ('team', 'membership_state', 'permissions', 'role')

def __init__(self, team: Team, state: ConnectionState, data: TeamMemberData):
self.team: Team = team
self.membership_state: TeamMembershipState = try_enum(TeamMembershipState, data['membership_state'])
self.permissions: List[str] = data['permissions']
self.role: TeamRole = try_enum(TeamRole, data['role'])
super().__init__(state=state, data=data['user'])

def __repr__(self) -> str:
if not self.is_migrated:
return f'<{self.__class__.__name__} id={self.id} username={self.name!r} global_name={self.global_name} ' \
f'discriminator={self.discriminator!r} membership_state={self.membership_state!r}>'
return f'<{self.__class__.__name__} id={self.id} username={self.name!r} global_name={self.global_name} ' \
f'membership_state={self.membership_state!r}>'
return (
f'<{self.__class__.__name__} role={self.role!r} id={self.id} username={self.username!r} '
f'global_name={self.global_name} membership_state={self.membership_state!r}>'
)
return (
f'<{self.__class__.__name__} role={self.role!r} id={self.id} username={self.username!r} '
f'discriminator={self.discriminator!r} global_name={self.global_name} '
f'membership_state={self.membership_state!r}>'
)

8 changes: 6 additions & 2 deletions discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
)
from typing_extensions import (
TypedDict,
NotRequired
NotRequired,
Literal
)

from .snowflake import SnowflakeID
Expand All @@ -44,12 +45,15 @@
'AppInfo',
)

TeamMembershipState = Literal[1, 2]
TeamRole = Literal['owner', 'admin', 'developer', 'read_only']

class TeamMember(TypedDict):
membership_state: int
membership_state: TeamMembershipState
permissions: List[str]
team_id: SnowflakeID
user: User
role: TeamRole


class Team(TypedDict):
Expand Down
31 changes: 31 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,37 @@ of :class:`enum.Enum`.

Represents a member currently in the team.

.. class:: TeamRole:

A :class:`TeamMember` can be one of four roles (owner, admin, developer, and read-only),
and each role inherits the access of those below it.
Represents the role of a team member retrieved through :func:`Bot.application_info`.

.. versionadded:: 2.0

.. attribute:: owner

Owners are the most permissiable role, and can take destructive, irreversible actions like deleting team-owned
apps or the team itself. Teams are limited to 1 owner.

.. attribute:: admin

Admins have similar access as an :attr:`~TeamRole.owner`,
except they cannot take destructive actions on the team or team-owned apps.

.. attribute:: developer

Developers can access information about team-owned apps, like the client secret or public key.
They can also take limited actions on team-owned apps,
like configuring interaction endpoints or resetting the bot token.
Members with the Developer role cannot manage the team or its members,
or take destructive actions on team-owned apps.

.. attribute:: read_only

Read-only members can access information about a team and any team-owned apps.
Some examples include getting the IDs of applications and exporting payout records.

.. class:: WebhookType

Represents the type of webhook that can be received.
Expand Down

1 comment on commit 288173e

@deez-changelogs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog for v2.0a615 (288173e) [branch developer]

New features

  • Add support for new team roles (288173e)

Please sign in to comment.