mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-03 18:42:43 +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.
|
||||
"""
|
||||
|
||||
__slots__ = ['user', 'id', 'is_private']
|
||||
|
||||
def __init__(self, user, id, **kwargs):
|
||||
self.user = user
|
||||
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.
|
||||
"""
|
||||
|
||||
class Colour(object):
|
||||
class Colour:
|
||||
"""Represents a Discord role colour. This class is similar
|
||||
to an (red, green, blue) tuple.
|
||||
|
||||
@ -50,6 +50,8 @@ class Colour(object):
|
||||
The raw integer colour value.
|
||||
"""
|
||||
|
||||
__slots__ = [ 'value' ]
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
@ -75,6 +75,10 @@ class Invite(Hashable):
|
||||
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):
|
||||
self.max_age = kwargs.get('max_age')
|
||||
self.code = kwargs.get('code')
|
||||
|
@ -64,8 +64,12 @@ class Member(User):
|
||||
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):
|
||||
super(Member, self).__init__(**user)
|
||||
super().__init__(**user)
|
||||
self.deaf = deaf
|
||||
self.mute = mute
|
||||
self.joined_at = parse_time(joined_at)
|
||||
|
@ -30,7 +30,7 @@ from .member import Member
|
||||
from .object import Object
|
||||
import re
|
||||
|
||||
class Message(object):
|
||||
class Message:
|
||||
"""Represents a message from Discord.
|
||||
|
||||
There should be no need to create one of these manually.
|
||||
|
@ -25,6 +25,8 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
class EqualityComparable:
|
||||
__slots__ = []
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and other.id == self.id
|
||||
|
||||
@ -34,5 +36,7 @@ class EqualityComparable:
|
||||
return True
|
||||
|
||||
class Hashable(EqualityComparable):
|
||||
__slots__ = []
|
||||
|
||||
def __hash__(self):
|
||||
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.
|
||||
"""
|
||||
|
||||
class Permissions(object):
|
||||
class Permissions:
|
||||
"""Wraps up the Discord permission value.
|
||||
|
||||
Supported operations:
|
||||
@ -50,6 +50,7 @@ class Permissions(object):
|
||||
were regular bools. This allows you to edit permissions.
|
||||
"""
|
||||
|
||||
__slots__ = [ 'value' ]
|
||||
def __init__(self, permissions=0, **kwargs):
|
||||
self.value = permissions
|
||||
|
||||
|
@ -53,8 +53,8 @@ class Role(Hashable):
|
||||
The name of the role.
|
||||
permissions : :class:`Permissions`
|
||||
Represents the role's permissions.
|
||||
color : :class:`Colour`
|
||||
Represents the role colour.
|
||||
colour : :class:`Colour`
|
||||
Represents the role colour. An alias exists under ``color``.
|
||||
hoist : bool
|
||||
Indicates if the role will be displayed separately from other members.
|
||||
position : int
|
||||
@ -64,6 +64,9 @@ class Role(Hashable):
|
||||
integrations such as Twitch.
|
||||
"""
|
||||
|
||||
__slots__ = ['id', 'name', 'permissions', 'color', 'colour', 'position',
|
||||
'managed', '_is_everyone', 'hoist' ]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self._is_everyone = kwargs.get('everyone', False)
|
||||
self.update(**kwargs)
|
||||
|
@ -81,7 +81,6 @@ class ConnectionState:
|
||||
self.messages.append(message)
|
||||
|
||||
def parse_message_delete(self, data):
|
||||
channel = self.get_channel(data.get('channel_id'))
|
||||
message_id = data.get('id')
|
||||
found = self._get_message(message_id)
|
||||
if found is not None:
|
||||
|
@ -53,11 +53,13 @@ class User:
|
||||
The avatar hash the user has. Could be None.
|
||||
"""
|
||||
|
||||
def __init__(self, username, id, discriminator, avatar, **kwargs):
|
||||
self.name = username
|
||||
self.id = id
|
||||
self.discriminator = discriminator
|
||||
self.avatar = avatar
|
||||
__slots__ = ['name', 'id', 'discriminator', 'avatar']
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.name = kwargs.get('username')
|
||||
self.id = kwargs.get('id')
|
||||
self.discriminator = kwargs.get('discriminator')
|
||||
self.avatar = kwargs.get('avatar')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
Loading…
x
Reference in New Issue
Block a user