diff options
| author | Rapptz <[email protected]> | 2016-12-30 04:34:42 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-03 09:52:06 -0500 |
| commit | dceba9d962483a0f423e53d472e18c8cd84c0759 (patch) | |
| tree | d39c4906807eb0d2ec55070715f237b82ecc12d2 | |
| parent | Fix handling of author update and missing type attribute in Message. (diff) | |
| download | discord.py-dceba9d962483a0f423e53d472e18c8cd84c0759.tar.xz discord.py-dceba9d962483a0f423e53d472e18c8cd84c0759.zip | |
Add useful repr to all data classes.
| -rw-r--r-- | discord/channel.py | 12 | ||||
| -rw-r--r-- | discord/colour.py | 3 | ||||
| -rw-r--r-- | discord/emoji.py | 3 | ||||
| -rw-r--r-- | discord/game.py | 3 | ||||
| -rw-r--r-- | discord/guild.py | 4 | ||||
| -rw-r--r-- | discord/invite.py | 3 | ||||
| -rw-r--r-- | discord/member.py | 6 | ||||
| -rw-r--r-- | discord/message.py | 3 | ||||
| -rw-r--r-- | discord/permissions.py | 3 | ||||
| -rw-r--r-- | discord/reaction.py | 3 | ||||
| -rw-r--r-- | discord/role.py | 3 | ||||
| -rw-r--r-- | discord/user.py | 3 |
12 files changed, 48 insertions, 1 deletions
diff --git a/discord/channel.py b/discord/channel.py index 78a06473..75d801ef 100644 --- a/discord/channel.py +++ b/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.""" diff --git a/discord/colour.py b/discord/colour.py index 1a4a6183..db75ad8a 100644 --- a/discord/colour.py +++ b/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) diff --git a/discord/emoji.py b/discord/emoji.py index 7b966c3d..c4817e3b 100644 --- a/discord/emoji.py +++ b/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.""" diff --git a/discord/game.py b/discord/game.py index 2ccabe28..aefc6efc 100644 --- a/discord/game.py +++ b/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) diff --git a/discord/guild.py b/discord/guild.py index d1f1c837..0428398d 100644 --- a/discord/guild.py +++ b/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) diff --git a/discord/invite.py b/discord/invite.py index 47fd494c..e6c8e295 100644 --- a/discord/invite.py +++ b/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.""" diff --git a/discord/member.py b/discord/member.py index 99412a68..bd6f4051 100644 --- a/discord/member.py +++ b/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 diff --git a/discord/message.py b/discord/message.py index a43deac3..9a49230c 100644 --- a/discord/message.py +++ b/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] diff --git a/discord/permissions.py b/discord/permissions.py index ba4d8834..507f77a5 100644 --- a/discord/permissions.py +++ b/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 diff --git a/discord/reaction.py b/discord/reaction.py index 2e47e397..d80f716b 100644 --- a/discord/reaction.py +++ b/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| diff --git a/discord/role.py b/discord/role.py index 7ea93a98..d517c8e8 100644 --- a/discord/role.py +++ b/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 diff --git a/discord/user.py b/discord/user.py index a27a06c6..77f257fe 100644 --- a/discord/user.py +++ b/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 |