mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-05 11:27:13 +00:00
Add __slots__ where appropriate to data classes.
This commit is contained in:
parent
4fa5b50d2b
commit
f1f0e169e4
@ -225,6 +225,8 @@ class PrivateChannel(Hashable):
|
|||||||
``True`` if the channel is a private channel (i.e. PM). ``True`` in this case.
|
``True`` if the channel is a private channel (i.e. PM). ``True`` in this case.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = ['user', 'id', 'is_private']
|
||||||
|
|
||||||
def __init__(self, user, id, **kwargs):
|
def __init__(self, user, id, **kwargs):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.id = id
|
self.id = id
|
||||||
|
@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Colour(object):
|
class Colour:
|
||||||
"""Represents a Discord role colour. This class is similar
|
"""Represents a Discord role colour. This class is similar
|
||||||
to an (red, green, blue) tuple.
|
to an (red, green, blue) tuple.
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ class Colour(object):
|
|||||||
The raw integer colour value.
|
The raw integer colour value.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = [ 'value' ]
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
|
@ -75,6 +75,10 @@ class Invite(Hashable):
|
|||||||
The channel the invite is for.
|
The channel the invite is for.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
__slots__ = [ 'max_age', 'code', 'server', 'revoked', 'created_at', 'uses',
|
||||||
|
'temporary', 'max_uses', 'xkcd', 'inviter', 'channel' ]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.max_age = kwargs.get('max_age')
|
self.max_age = kwargs.get('max_age')
|
||||||
self.code = kwargs.get('code')
|
self.code = kwargs.get('code')
|
||||||
|
@ -64,8 +64,12 @@ class Member(User):
|
|||||||
The server that the member belongs to.
|
The server that the member belongs to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = [ 'deaf', 'mute', 'self_mute', 'self_deaf', 'is_afk',
|
||||||
|
'voice_channel', 'roles', 'joined_at', 'status', 'game_id',
|
||||||
|
'server' ]
|
||||||
|
|
||||||
def __init__(self, deaf, joined_at, user, roles, mute, **kwargs):
|
def __init__(self, deaf, joined_at, user, roles, mute, **kwargs):
|
||||||
super(Member, self).__init__(**user)
|
super().__init__(**user)
|
||||||
self.deaf = deaf
|
self.deaf = deaf
|
||||||
self.mute = mute
|
self.mute = mute
|
||||||
self.joined_at = parse_time(joined_at)
|
self.joined_at = parse_time(joined_at)
|
||||||
|
@ -30,7 +30,7 @@ from .member import Member
|
|||||||
from .object import Object
|
from .object import Object
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class Message(object):
|
class Message:
|
||||||
"""Represents a message from Discord.
|
"""Represents a message from Discord.
|
||||||
|
|
||||||
There should be no need to create one of these manually.
|
There should be no need to create one of these manually.
|
||||||
|
@ -25,6 +25,8 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class EqualityComparable:
|
class EqualityComparable:
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return isinstance(other, self.__class__) and other.id == self.id
|
return isinstance(other, self.__class__) and other.id == self.id
|
||||||
|
|
||||||
@ -34,5 +36,7 @@ class EqualityComparable:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
class Hashable(EqualityComparable):
|
class Hashable(EqualityComparable):
|
||||||
|
__slots__ = []
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.id)
|
return hash(self.id)
|
||||||
|
@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Permissions(object):
|
class Permissions:
|
||||||
"""Wraps up the Discord permission value.
|
"""Wraps up the Discord permission value.
|
||||||
|
|
||||||
Supported operations:
|
Supported operations:
|
||||||
@ -50,6 +50,7 @@ class Permissions(object):
|
|||||||
were regular bools. This allows you to edit permissions.
|
were regular bools. This allows you to edit permissions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = [ 'value' ]
|
||||||
def __init__(self, permissions=0, **kwargs):
|
def __init__(self, permissions=0, **kwargs):
|
||||||
self.value = permissions
|
self.value = permissions
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ class Role(Hashable):
|
|||||||
The name of the role.
|
The name of the role.
|
||||||
permissions : :class:`Permissions`
|
permissions : :class:`Permissions`
|
||||||
Represents the role's permissions.
|
Represents the role's permissions.
|
||||||
color : :class:`Colour`
|
colour : :class:`Colour`
|
||||||
Represents the role colour.
|
Represents the role colour. An alias exists under ``color``.
|
||||||
hoist : bool
|
hoist : bool
|
||||||
Indicates if the role will be displayed separately from other members.
|
Indicates if the role will be displayed separately from other members.
|
||||||
position : int
|
position : int
|
||||||
@ -64,6 +64,9 @@ class Role(Hashable):
|
|||||||
integrations such as Twitch.
|
integrations such as Twitch.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = ['id', 'name', 'permissions', 'color', 'colour', 'position',
|
||||||
|
'managed', '_is_everyone', 'hoist' ]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self._is_everyone = kwargs.get('everyone', False)
|
self._is_everyone = kwargs.get('everyone', False)
|
||||||
self.update(**kwargs)
|
self.update(**kwargs)
|
||||||
|
@ -81,7 +81,6 @@ class ConnectionState:
|
|||||||
self.messages.append(message)
|
self.messages.append(message)
|
||||||
|
|
||||||
def parse_message_delete(self, data):
|
def parse_message_delete(self, data):
|
||||||
channel = self.get_channel(data.get('channel_id'))
|
|
||||||
message_id = data.get('id')
|
message_id = data.get('id')
|
||||||
found = self._get_message(message_id)
|
found = self._get_message(message_id)
|
||||||
if found is not None:
|
if found is not None:
|
||||||
|
@ -53,11 +53,13 @@ class User:
|
|||||||
The avatar hash the user has. Could be None.
|
The avatar hash the user has. Could be None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, username, id, discriminator, avatar, **kwargs):
|
__slots__ = ['name', 'id', 'discriminator', 'avatar']
|
||||||
self.name = username
|
|
||||||
self.id = id
|
def __init__(self, **kwargs):
|
||||||
self.discriminator = discriminator
|
self.name = kwargs.get('username')
|
||||||
self.avatar = avatar
|
self.id = kwargs.get('id')
|
||||||
|
self.discriminator = kwargs.get('discriminator')
|
||||||
|
self.avatar = kwargs.get('avatar')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user