Skip to content

Commit

Permalink
update types subpackage with latest docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NCPlayz committed Jun 8, 2021
1 parent a7ae2eb commit 94bbdc1
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 46 deletions.
4 changes: 2 additions & 2 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):

# special cases for role add/remove
if attr == '$add':
self._handle_role(self.before, self.after, entry, elem['new_value'])
self._handle_role(self.before, self.after, entry, elem['new_value']) # type: ignore
continue
elif attr == '$remove':
self._handle_role(self.after, self.before, entry, elem['new_value'])
self._handle_role(self.after, self.before, entry, elem['new_value']) # type: ignore
continue

try:
Expand Down
21 changes: 11 additions & 10 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
from .types import (
interactions,
invite,
stage_instance,
channel,
widget,
)
from .types.snowflake import Snowflake

Expand Down Expand Up @@ -969,10 +970,10 @@ def get_audit_logs(self, guild_id, limit=100, before=None, after=None, user_id=N
r = Route('GET', '/guilds/{guild_id}/audit-logs', guild_id=guild_id)
return self.request(r, params=params)

def get_widget(self, guild_id):
def get_widget(self, guild_id: Snowflake) -> Response[widget.Widget]:
return self.request(Route('GET', '/guilds/{guild_id}/widget.json', guild_id=guild_id))
def edit_widget(self, guild_id, payload):

def edit_widget(self, guild_id: Snowflake, payload) -> Response[widget.WidgetSettings]:
return self.request(Route('PATCH', '/guilds/{guild_id}/widget', guild_id=guild_id), json=payload)

# Invite management
Expand Down Expand Up @@ -1009,20 +1010,20 @@ def create_invite(

return self.request(r, reason=reason, json=payload)

def get_invite(self, invite_id, *, with_counts=True, with_expiration=True):
def get_invite(self, invite_id: str, *, with_counts: bool = True, with_expiration: bool = True) -> Response[invite.Invite]:
params = {
'with_counts': int(with_counts),
'with_expiration': int(with_expiration),
}
return self.request(Route('GET', '/invites/{invite_id}', invite_id=invite_id), params=params)

def invites_from(self, guild_id):
def invites_from(self, guild_id: Snowflake) -> Response[List[invite.Invite]]:
return self.request(Route('GET', '/guilds/{guild_id}/invites', guild_id=guild_id))

def invites_from_channel(self, channel_id):
def invites_from_channel(self, channel_id: Snowflake) -> Response[List[invite.Invite]]:
return self.request(Route('GET', '/channels/{channel_id}/invites', channel_id=channel_id))

def delete_invite(self, invite_id, *, reason=None):
def delete_invite(self, invite_id: str, *, reason: bool = None) -> Response[None]:
return self.request(Route('DELETE', '/invites/{invite_id}', invite_id=invite_id), reason=reason)

# Role management
Expand Down Expand Up @@ -1087,10 +1088,10 @@ def move_member(self, user_id, guild_id, channel_id, *, reason=None):

# Stage instance management

def get_stage_instance(self, channel_id: Snowflake) -> Response[stage_instance.StageInstance]:
def get_stage_instance(self, channel_id: Snowflake) -> Response[channel.StageInstance]:
return self.request(Route('GET', '/stage-instances/{channel_id}', channel_id=channel_id))

def create_stage_instance(self, **payload) -> Response[stage_instance.StageInstance]:
def create_stage_instance(self, **payload) -> Response[channel.StageInstance]:
valid_keys = (
'channel_id',
'topic',
Expand Down
148 changes: 141 additions & 7 deletions discord/types/audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@

from __future__ import annotations

from typing import Any, List, Literal, Optional, TypedDict
from typing import List, Literal, Optional, TypedDict, Union
from .webhook import Webhook
from .integration import PartialIntegration
from .guild import MFALevel, VerificationLevel, ExplicitContentFilterLevel, DefaultMessageNotificationLevel
from .integration import IntegrationExpireBehavior, PartialIntegration
from .user import User
from .snowflake import Snowflake
from .role import Role
from .channel import ChannelType, VideoQualityMode, PermissionOverwrite

AuditLogEvent = Literal[
1,
Expand Down Expand Up @@ -69,10 +72,141 @@
]


class AuditLogChange(TypedDict):
key: str
new_value: Any
old_value: Any
class _AuditLogChange_Str(TypedDict):
key: Literal[
'name', 'description', 'preferred_locale', 'vanity_url_code', 'topic', 'code', 'allow', 'deny', 'permissions'
]
new_value: str
old_value: str


class _AuditLogChange_AssetHash(TypedDict):
key: Literal['icon_hash', 'splash_hash', 'discovery_splash_hash', 'banner_hash', 'avatar_hash']
new_value: str
old_value: str


class _AuditLogChange_Snowflake(TypedDict):
key: Literal[
'id',
'owner_id',
'afk_channel_id',
'rules_channel_id',
'public_updates_channel_id',
'widget_channel_id',
'system_channel_id',
'application_id',
'channel_id',
'inviter_id',
]
new_value: Snowflake
old_value: Snowflake


class _AuditLogChange_Bool(TypedDict):
key: Literal[
'widget_enabled',
'nsfw',
'hoist',
'mentionable',
'temporary',
'deaf',
'mute',
'nick',
'enabled_emoticons',
'region',
'rtc_region',
]
new_value: bool
old_value: bool


class _AuditLogChange_Int(TypedDict):
key: Literal[
'afk_timeout',
'prune_delete_days',
'position',
'bitrate',
'rate_limit_per_user',
'color',
'max_uses',
'max_age',
'user_limit',
]
new_value: int
old_value: int


class _AuditLogChange_ListRole(TypedDict):
key: Literal['$add', '$remove']
new_value: List[Role]
old_value: List[Role]


class _AuditLogChange_MFALevel(TypedDict):
key: Literal['mfa_level']
new_value: MFALevel
old_value: MFALevel


class _AuditLogChange_VerificationLevel(TypedDict):
key: Literal['verification_level']
new_value: VerificationLevel
old_value: VerificationLevel


class _AuditLogChange_ExplicitContentFilter(TypedDict):
key: Literal['explicit_content_filter']
new_value: ExplicitContentFilterLevel
old_value: ExplicitContentFilterLevel


class _AuditLogChange_DefaultMessageNotificationLevel(TypedDict):
key: Literal['default_message_notifications']
new_value: DefaultMessageNotificationLevel
old_value: DefaultMessageNotificationLevel


class _AuditLogChange_ChannelType(TypedDict):
key: Literal['type']
new_value: ChannelType
old_value: ChannelType


class _AuditLogChange_IntegrationExpireBehaviour(TypedDict):
key: Literal['expire_behavior']
new_value: IntegrationExpireBehavior
old_value: IntegrationExpireBehavior


class _AuditLogChange_VideoQualityMode(TypedDict):
key: Literal['video_quality_mode']
new_value: VideoQualityMode
old_value: VideoQualityMode


class _AuditLogChange_Overwrites(TypedDict):
key: Literal['permission_overwrites']
new_value: List[PermissionOverwrite]
old_value: List[PermissionOverwrite]


AuditLogChange = Union[
_AuditLogChange_Str,
_AuditLogChange_AssetHash,
_AuditLogChange_Snowflake,
_AuditLogChange_Int,
_AuditLogChange_Bool,
_AuditLogChange_ListRole,
_AuditLogChange_MFALevel,
_AuditLogChange_VerificationLevel,
_AuditLogChange_ExplicitContentFilter,
_AuditLogChange_DefaultMessageNotificationLevel,
_AuditLogChange_ChannelType,
_AuditLogChange_IntegrationExpireBehaviour,
_AuditLogChange_VideoQualityMode,
_AuditLogChange_Overwrites,
]


class AuditEntryInfo(TypedDict):
Expand All @@ -94,7 +228,7 @@ class _AuditLogEntryOptional(TypedDict, total=False):

class AuditLogEntry(_AuditLogEntryOptional):
target_id: Optional[str]
user_id: Snowflake
user_id: Optional[Snowflake]
id: Snowflake
action_type: AuditLogEvent

Expand Down
70 changes: 49 additions & 21 deletions discord/types/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
DEALINGS IN THE SOFTWARE.
"""

from typing import List, Literal, Optional, TypedDict, Union
from .user import PartialUser
from .snowflake import Snowflake
from typing import List, Literal, Optional, TypedDict


class PermissionOverwrite(TypedDict):
Expand All @@ -37,60 +37,88 @@ class PermissionOverwrite(TypedDict):
ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 13]


class PartialChannel(TypedDict):
id: str
type: ChannelType
class _BaseChannel(TypedDict):
id: Snowflake
name: str


class _TextChannelOptional(PartialChannel, total=False):
class _BaseGuildChannel(_BaseChannel):
guild_id: Snowflake
position: int
permission_overwrites: List[PermissionOverwrite]
nsfw: bool
parent_id: Optional[Snowflake]


class PartialChannel(_BaseChannel):
type: ChannelType


class _TextChannelOptional(TypedDict, total=False):
topic: str
last_message_id: Optional[Snowflake]
last_pin_timestamp: str
rate_limit_per_user: int


class _VoiceChannelOptional(PartialChannel, total=False):
class TextChannel(_BaseGuildChannel, _TextChannelOptional):
type: Literal[0]


class NewsChannel(_BaseGuildChannel, _TextChannelOptional):
type: Literal[5]


VideoQualityMode = Literal[1, 2]


class _VoiceChannelOptional(TypedDict, total=False):
rtc_region: Optional[str]
bitrate: int
user_limit: int
video_quality_mode: VideoQualityMode


class _CategoryChannelOptional(PartialChannel, total=False):
...
class VoiceChannel(_BaseGuildChannel, _VoiceChannelOptional):
type: Literal[2]


class _StoreChannelOptional(PartialChannel, total=False):
...
class CategoryChannel(_BaseGuildChannel):
type: Literal[4]


class _StageChannelOptional(PartialChannel, total=False):
class StoreChannel(_BaseGuildChannel):
type: Literal[6]


class _StageChannelOptional(TypedDict, total=False):
rtc_region: Optional[str]
bitrate: int
user_limit: int
topic: str


class GuildChannel(
_TextChannelOptional, _VoiceChannelOptional, _CategoryChannelOptional, _StoreChannelOptional, _StageChannelOptional
):
guild_id: Snowflake
position: int
permission_overwrites: List[PermissionOverwrite]
nsfw: bool
parent_id: Optional[Snowflake]
class StageChannel(_BaseGuildChannel, _StageChannelOptional):
type: Literal[13]


class DMChannel(PartialChannel):
GuildChannel = Union[TextChannel, NewsChannel, VoiceChannel, CategoryChannel, StoreChannel, StageChannel]


class DMChannel(_BaseChannel):
type: Literal[1]
last_message_id: Optional[Snowflake]
recipients: List[PartialUser]


class GroupDMChannel(DMChannel):
class GroupDMChannel(_BaseChannel):
type: Literal[3]
icon: Optional[str]
owner_id: Snowflake


Channel = Union[GuildChannel, DMChannel, GroupDMChannel]

PrivacyLevel = Literal[1, 2]


Expand Down
Loading

0 comments on commit 94bbdc1

Please sign in to comment.