Browse Source

Add useful repr to all data classes.

pull/447/head
Rapptz 8 years ago
parent
commit
dceba9d962
  1. 12
      discord/channel.py
  2. 3
      discord/colour.py
  3. 3
      discord/emoji.py
  4. 3
      discord/game.py
  5. 4
      discord/guild.py
  6. 3
      discord/invite.py
  7. 6
      discord/member.py
  8. 3
      discord/message.py
  9. 3
      discord/permissions.py
  10. 3
      discord/reaction.py
  11. 3
      discord/role.py
  12. 3
      discord/user.py

12
discord/channel.py

@ -341,6 +341,9 @@ class TextChannel(discord.abc.MessageChannel, CommonGuildChannel):
self.id = int(data['id'])
self._update(guild, data)
def __repr__(self):
return '<TextChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
def _update(self, guild, data):
self.guild = guild
self.name = data['name']
@ -435,6 +438,9 @@ class VoiceChannel(CommonGuildChannel):
self._update(guild, data)
self.voice_members = []
def __repr__(self):
return '<VoiceChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
def _update(self, guild, data):
self.guild = guild
self.name = data['name']
@ -522,6 +528,9 @@ class DMChannel(discord.abc.MessageChannel, Hashable):
def __str__(self):
return 'Direct Message with %s' % self.recipient
def __repr__(self):
return '<DMChannel id={0.id} recipient={0.recipient!r}>'.format(self)
@property
def created_at(self):
"""Returns the direct message channel's creation time in UTC."""
@ -620,6 +629,9 @@ class GroupChannel(discord.abc.MessageChannel, Hashable):
return ', '.join(map(lambda x: x.name, self.recipients))
def __repr__(self):
return '<GroupChannel id={0.id} name={0.name!r}>'.format(self)
@property
def icon_url(self):
"""Returns the channel's icon URL if available or an empty string otherwise."""

3
discord/colour.py

@ -67,6 +67,9 @@ class Colour:
def __str__(self):
return '#{:0>6x}'.format(self.value)
def __repr__(self):
return '<Colour value=%s>' % self.value
def __hash__(self):
return hash(self.value)

3
discord/emoji.py

@ -103,6 +103,9 @@ class Emoji(Hashable):
def __str__(self):
return "<:{0.name}:{0.id}>".format(self)
def __repr__(self):
return '<Emoji id={0.id} name={0.name!r}>'.format(self)
@property
def created_at(self):
"""Returns the emoji's creation time in UTC."""

3
discord/game.py

@ -61,6 +61,9 @@ class Game:
def __str__(self):
return self.name
def __repr__(self):
return '<Game name={0.name!r} type={0.type!r} url={0.url!r}>'.format(self)
def _iterator(self):
for attr in self.__slots__:
value = getattr(self, attr, None)

4
discord/guild.py

@ -144,6 +144,10 @@ class Guild(Hashable):
def __str__(self):
return self.name
def __repr__(self):
chunked = getattr(self, '_member_count', None) == len(self._members)
return '<Guild id={0.id} name={0.name!r} chunked={1}>'.format(self, chunked)
def _update_voice_state(self, data, channel_id):
user_id = int(data['user_id'])
channel = self.get_channel(channel_id)

3
discord/invite.py

@ -95,6 +95,9 @@ class Invite(Hashable):
def __str__(self):
return self.url
def __repr__(self):
return '<Invite code={0.code!r}>'.format(self)
@property
def id(self):
"""Returns the proper code portion of the invite."""

6
discord/member.py

@ -152,7 +152,11 @@ class Member:
self.nick = data.get('nick', None)
def __str__(self):
return self._user.__str__()
return str(self._user)
def __repr__(self):
return '<Member id={1.id} name={1.name!r} discriminator={1.discriminator!r}' \
' bot={1.bot} nick={0.nick!r} guild={0.guild!r}>'.format(self, self._user)
def __eq__(self, other):
return isinstance(other, Member) and other._user.id == self._user.id and self.guild.id == other.guild.id

3
discord/message.py

@ -123,6 +123,9 @@ class Message:
self.reactions = [Reaction(message=self, data=d) for d in data.get('reactions', [])]
self._update(channel, data)
def __repr__(self):
return '<Message id={0.id} pinned={0.pinned} author={0.author!r}>'.format(self)
def _try_patch(self, data, key, transform):
try:
value = data[key]

3
discord/permissions.py

@ -80,6 +80,9 @@ class Permissions:
def __hash__(self):
return hash(self.value)
def __repr__(self):
return '<Permissions value=%s>' % self.value
def _perm_iterator(self):
for attr in dir(self):
# check if it's a property, because if so it's a permission

3
discord/reaction.py

@ -83,6 +83,9 @@ class Reaction:
def __hash__(self):
return hash(self.emoji)
def __repr__(self):
return '<Reaction emoji={0.emoji!r} me={0.me} count={0.count}>'.format(self)
@asyncio.coroutine
def users(self, limit=100, after=None):
"""|coro|

3
discord/role.py

@ -92,6 +92,9 @@ class Role(Hashable):
def __str__(self):
return self.name
def __repr__(self):
return '<Role id={0.id} name={0.name!r}>'.format(self)
def __lt__(self, other):
if not isinstance(other, Role) or not isinstance(self, Role):
return NotImplemented

3
discord/user.py

@ -80,6 +80,9 @@ class User:
def __hash__(self):
return hash(self.id)
def __repr__(self):
return '<User id={0.id} name={0.name!r} discriminator={0.discriminator!r} bot={0.bot}>'.format(self)
@property
def avatar_url(self):
"""Returns a friendly URL version of the avatar variable the user has. An empty string if

Loading…
Cancel
Save