aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadir Chowdhury <[email protected]>2021-04-07 12:56:56 +0100
committerGitHub <[email protected]>2021-04-07 07:56:56 -0400
commit87e64dff0627abb460d2d1d71ea272d224c38add (patch)
tree5437ce8a101d81df02de6636fb01e6dd1772b3db
parentAdd typing for flags (diff)
downloaddiscord.py-87e64dff0627abb460d2d1d71ea272d224c38add.tar.xz
discord.py-87e64dff0627abb460d2d1d71ea272d224c38add.zip
Add typings for channels and `PartialUser`
-rw-r--r--discord/types/channel.py91
-rw-r--r--discord/types/snowflake.py28
-rw-r--r--discord/types/user.py33
3 files changed, 152 insertions, 0 deletions
diff --git a/discord/types/channel.py b/discord/types/channel.py
new file mode 100644
index 00000000..95644392
--- /dev/null
+++ b/discord/types/channel.py
@@ -0,0 +1,91 @@
+"""
+The MIT License (MIT)
+
+Copyright (c) 2015-present Rapptz
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+"""
+
+from .user import PartialUser
+from .snowflake import Snowflake
+from typing import List, Literal, Optional, TypedDict
+
+
+class PermissionOverwrite(TypedDict):
+ id: Snowflake
+ type: Literal[0, 1]
+ allow: str
+ deny: str
+
+
+ChannelType = Literal[0, 1, 2, 3, 4, 5, 6, 13]
+
+
+class PartialChannel(TypedDict):
+ id: str
+ type: ChannelType
+ name: str
+
+
+class _TextChannelOptional(PartialChannel, total=False):
+ topic: str
+ last_message_id: Optional[Snowflake]
+ last_pin_timestamp: int
+ rate_limit_per_user: int
+
+
+class _VoiceChannelOptional(PartialChannel, total=False):
+ rtc_region: Optional[str]
+ bitrate: int
+ user_limit: int
+
+
+class _CategoryChannelOptional(PartialChannel, total=False):
+ ...
+
+
+class _StoreChannelOptional(PartialChannel, total=False):
+ ...
+
+
+class _StageChannelOptional(PartialChannel, 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 DMChannel(PartialChannel):
+ last_message_id: Optional[Snowflake]
+ recipients: List[PartialUser]
+
+
+class GroupDMChannel(DMChannel):
+ icon: Optional[str]
+ owner_id: Snowflake
diff --git a/discord/types/snowflake.py b/discord/types/snowflake.py
new file mode 100644
index 00000000..341bd767
--- /dev/null
+++ b/discord/types/snowflake.py
@@ -0,0 +1,28 @@
+"""
+The MIT License (MIT)
+
+Copyright (c) 2015-present Rapptz
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+"""
+
+from typing import List
+
+Snowflake = str
+SnowflakeList = List[Snowflake]
diff --git a/discord/types/user.py b/discord/types/user.py
new file mode 100644
index 00000000..2951254f
--- /dev/null
+++ b/discord/types/user.py
@@ -0,0 +1,33 @@
+"""
+The MIT License (MIT)
+
+Copyright (c) 2015-present Rapptz
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+"""
+
+from .snowflake import Snowflake
+from typing import Optional, TypedDict
+
+
+class PartialUser(TypedDict):
+ id: Snowflake
+ username: str
+ discriminator: str
+ avatar: Optional[str]