Browse Source

update types subpackage with latest docs

pull/7030/head
Nadir Chowdhury 4 years ago
committed by GitHub
parent
commit
94bbdc154c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      discord/audit_logs.py
  2. 21
      discord/http.py
  3. 148
      discord/types/audit_log.py
  4. 70
      discord/types/channel.py
  5. 8
      discord/types/interactions.py
  6. 1
      discord/types/invite.py
  7. 2
      discord/types/message.py
  8. 7
      discord/types/widget.py

4
discord/audit_logs.py

@ -222,10 +222,10 @@ class AuditLogChanges:
# 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:

21
discord/http.py

@ -44,7 +44,8 @@ if TYPE_CHECKING:
from .types import (
interactions,
invite,
stage_instance,
channel,
widget,
)
from .types.snowflake import Snowflake
@ -969,10 +970,10 @@ class HTTPClient:
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
@ -1009,20 +1010,20 @@ class HTTPClient:
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
@ -1087,10 +1088,10 @@ class HTTPClient:
# 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',

148
discord/types/audit_log.py

@ -24,11 +24,14 @@ DEALINGS IN THE SOFTWARE.
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,
@ -69,10 +72,141 @@ AuditLogEvent = Literal[
]
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):
@ -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

70
discord/types/channel.py

@ -22,9 +22,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
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):
@ -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]

8
discord/types/interactions.py

@ -26,7 +26,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Dict, TypedDict, Union, List, Literal
from .snowflake import Snowflake
from .components import ComponentType
from .components import Component, ComponentType
from .embed import Embed
from .channel import ChannelType
from .member import Member
@ -87,7 +87,7 @@ class GuildApplicationCommandPermissions(PartialGuildApplicationCommandPermissio
guild_id: Snowflake
InteractionType = Literal[1, 2]
InteractionType = Literal[1, 2, 3]
class _ApplicationCommandInteractionDataOptionOptional(TypedDict, total=False):
@ -149,16 +149,16 @@ class Interaction(_InteractionOptional):
token: str
version: int
class InteractionApplicationCommandCallbackData(TypedDict, total=False):
tts: bool
content: str
embeds: List[Embed]
allowed_mentions: AllowedMentions
flags: int
components: List[Component]
InteractionResponseType = Literal[1, 2, 3, 4, 5, 6, 7]
InteractionResponseType = Literal[1, 4, 5, 6, 7]
class _InteractionResponseOptional(TypedDict, total=False):

1
discord/types/invite.py

@ -49,6 +49,7 @@ class _InviteMetadata(TypedDict, total=False):
max_age: int
temporary: bool
created_at: str
expires_at: Optional[str]
class IncompleteInvite(_InviteMetadata):

2
discord/types/message.py

@ -102,7 +102,6 @@ class Sticker(_StickerOptional):
name: str
description: str
asset: str
preview_asset: str
format_type: StickerFormatType
@ -115,6 +114,7 @@ class _MessageOptional(TypedDict, total=False):
webhook_id: Snowflake
activity: MessageActivity
application: MessageApplication
application_id: Snowflake
message_reference: MessageReference
flags: int
stickers: List[Sticker]

7
discord/types/widget.py

@ -22,7 +22,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import List, TypedDict
from typing import List, Optional, TypedDict
from .activity import Activity
from .snowflake import Snowflake
from .user import User
@ -56,3 +56,8 @@ class Widget(_WidgetOptional):
id: Snowflake
name: str
instant_invite: str
class WidgetSettings(TypedDict):
enabled: bool
channel_id: Optional[Snowflake]

Loading…
Cancel
Save