mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-03 10:32:42 +00:00
Make __repr__ slightly more detailed and add a few missing ones.
This includes raw events (which didn't have any) and a few other types that were missing them. Upon review some more useful fields were added to the repr output which would be more useful during debugging.
This commit is contained in:
parent
ab6dd2a27a
commit
2cd6d771ec
@ -152,6 +152,18 @@ class Activity(_ActivityTag):
|
||||
self.session_id = kwargs.pop('session_id', None)
|
||||
self.type = try_enum(ActivityType, kwargs.pop('type', -1))
|
||||
|
||||
def __repr__(self):
|
||||
attrs = (
|
||||
'type',
|
||||
'name',
|
||||
'url',
|
||||
'details',
|
||||
'application_id',
|
||||
'session_id',
|
||||
)
|
||||
mapped = ' '.join('%s=%r' % (attr, getattr(self, attr)) for attr in attrs)
|
||||
return '<Activity %s>' % mapped
|
||||
|
||||
def to_dict(self):
|
||||
ret = {}
|
||||
for attr in self.__slots__:
|
||||
|
@ -93,7 +93,8 @@ class AuditLogDiff:
|
||||
return iter(self.__dict__.items())
|
||||
|
||||
def __repr__(self):
|
||||
return '<AuditLogDiff attrs={0!r}>'.format(tuple(self.__dict__))
|
||||
values = ' '.join('%s=%r' % item for item in self.__dict__.items())
|
||||
return '<AuditLogDiff %s>' % values
|
||||
|
||||
class AuditLogChanges:
|
||||
TRANSFORMERS = {
|
||||
@ -164,6 +165,9 @@ class AuditLogChanges:
|
||||
self.after.color = self.after.colour
|
||||
self.before.color = self.before.colour
|
||||
|
||||
def __repr__(self):
|
||||
return '<AuditLogChanges before=%r after=%r>' % (self.before, self.after)
|
||||
|
||||
def _handle_role(self, first, second, entry, elem):
|
||||
if not hasattr(first, 'roles'):
|
||||
setattr(first, 'roles', [])
|
||||
|
@ -107,7 +107,15 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
||||
self._update(guild, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<TextChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
||||
attrs = [
|
||||
('id', self.id),
|
||||
('name', self.name),
|
||||
('position', self.position),
|
||||
('nsfw', self.nsfw),
|
||||
('news', self.is_news()),
|
||||
('category_id', self.category_id)
|
||||
]
|
||||
return '<%s %s>' % (self.__class__.__name__, ' '.join('%s=%r' % t for t in attrs))
|
||||
|
||||
def _update(self, guild, data):
|
||||
self.guild = guild
|
||||
@ -491,7 +499,15 @@ class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
|
||||
self._update(guild, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<VoiceChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
||||
attrs = [
|
||||
('id', self.id),
|
||||
('name', self.name),
|
||||
('position', self.position),
|
||||
('bitrate', self.bitrate),
|
||||
('user_limit', self.user_limit),
|
||||
('category_id', self.category_id)
|
||||
]
|
||||
return '<%s %s>' % (self.__class__.__name__, ' '.join('%s=%r' % t for t in attrs))
|
||||
|
||||
def _get_voice_client_key(self):
|
||||
return self.guild.id, 'guild_id'
|
||||
@ -629,7 +645,7 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
|
||||
self._update(guild, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<CategoryChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
||||
return '<CategoryChannel id={0.id} name={0.name!r} position={0.position} nsfw={0.nsfw}>'.format(self)
|
||||
|
||||
def _update(self, guild, data):
|
||||
self.guild = guild
|
||||
@ -788,7 +804,7 @@ class StoreChannel(discord.abc.GuildChannel, Hashable):
|
||||
self._update(guild, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<StoreChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
||||
return '<StoreChannel id={0.id} name={0.name!r} position={0.position} nsfw={0.nsfw}>'.format(self)
|
||||
|
||||
def _update(self, guild, data):
|
||||
self.guild = guild
|
||||
@ -1030,7 +1046,7 @@ class GroupChannel(discord.abc.Messageable, Hashable):
|
||||
|
||||
@property
|
||||
def icon_url(self):
|
||||
""":class:`Asset`: Returns the channel's icon asset."""
|
||||
""":class:`Asset`: Returns the channel's icon asset if available."""
|
||||
return Asset._from_icon(self._state, self, 'channel')
|
||||
|
||||
@property
|
||||
|
@ -206,7 +206,7 @@ class Emoji:
|
||||
return "<:{0.name}:{0.id}>".format(self)
|
||||
|
||||
def __repr__(self):
|
||||
return '<Emoji id={0.id} name={0.name!r}>'.format(self)
|
||||
return '<Emoji id={0.id} name={0.name!r} animated={0.animated} managed={0.managed}>'.format(self)
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, (PartialEmoji, Emoji)) and self.id == other.id
|
||||
|
@ -160,7 +160,12 @@ class Guild(Hashable):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
return '<Guild id={0.id} name={0.name!r} chunked={0.chunked}>'.format(self)
|
||||
attrs = (
|
||||
'id', 'name', 'shard_id', 'chunked'
|
||||
)
|
||||
resolved = ['%s=%r' % (attr, getattr(self, attr)) for attr in attrs]
|
||||
resolved.append('member_count=%r' % getattr(self, '_member_count', None))
|
||||
return '<Guild %s>' % ' '.join(resolved)
|
||||
|
||||
def _update_voice_state(self, data, channel_id):
|
||||
user_id = int(data['user_id'])
|
||||
|
@ -294,7 +294,9 @@ class Invite(Hashable):
|
||||
return self.url
|
||||
|
||||
def __repr__(self):
|
||||
return '<Invite code={0.code!r}>'.format(self)
|
||||
return '<Invite code={0.code!r} guild={0.guild!r} ' \
|
||||
'online={0.approximate_presence_count} ' \
|
||||
'members={0.approximate_member_count}>'.format(self)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.code)
|
||||
|
@ -78,6 +78,9 @@ class Attachment:
|
||||
""":class:`bool`: Whether this attachment contains a spoiler."""
|
||||
return self.filename.startswith('SPOILER_')
|
||||
|
||||
def __repr__(self):
|
||||
return '<Attachment id={0.id} filename={0.filename!r} url={0.url!r}>'.format(self)
|
||||
|
||||
async def save(self, fp, *, seek_begin=True, use_cached=False):
|
||||
"""|coro|
|
||||
|
||||
@ -263,7 +266,7 @@ class Message:
|
||||
self._update(channel, data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<Message id={0.id} pinned={0.pinned} author={0.author!r}>'.format(self)
|
||||
return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r}>'.format(self)
|
||||
|
||||
def _try_patch(self, data, key, transform=None):
|
||||
try:
|
||||
|
@ -64,6 +64,9 @@ class Object(Hashable):
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
|
||||
def __repr__(self):
|
||||
return '<Object id=%r>' % self.id
|
||||
|
||||
@property
|
||||
def created_at(self):
|
||||
"""Returns the snowflake's creation time in UTC."""
|
||||
|
@ -24,7 +24,12 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
class RawMessageDeleteEvent:
|
||||
class _RawReprMixin:
|
||||
def __repr__(self):
|
||||
value = ' '.join('%s=%r' % (attr, getattr(self, attr)) for attr in self.__slots__)
|
||||
return '<%s %s>' % (self.__class__.__name__, value)
|
||||
|
||||
class RawMessageDeleteEvent(_RawReprMixin):
|
||||
"""Represents the event payload for a :func:`on_raw_message_delete` event.
|
||||
|
||||
Attributes
|
||||
@ -50,7 +55,7 @@ class RawMessageDeleteEvent:
|
||||
except KeyError:
|
||||
self.guild_id = None
|
||||
|
||||
class RawBulkMessageDeleteEvent:
|
||||
class RawBulkMessageDeleteEvent(_RawReprMixin):
|
||||
"""Represents the event payload for a :func:`on_raw_bulk_message_delete` event.
|
||||
|
||||
Attributes
|
||||
@ -77,7 +82,7 @@ class RawBulkMessageDeleteEvent:
|
||||
except KeyError:
|
||||
self.guild_id = None
|
||||
|
||||
class RawMessageUpdateEvent:
|
||||
class RawMessageUpdateEvent(_RawReprMixin):
|
||||
"""Represents the payload for a :func:`on_raw_message_edit` event.
|
||||
|
||||
Attributes
|
||||
@ -98,7 +103,7 @@ class RawMessageUpdateEvent:
|
||||
self.data = data
|
||||
self.cached_message = None
|
||||
|
||||
class RawReactionActionEvent:
|
||||
class RawReactionActionEvent(_RawReprMixin):
|
||||
"""Represents the payload for a :func:`on_raw_reaction_add` or
|
||||
:func:`on_raw_reaction_remove` event.
|
||||
|
||||
@ -129,7 +134,7 @@ class RawReactionActionEvent:
|
||||
except KeyError:
|
||||
self.guild_id = None
|
||||
|
||||
class RawReactionClearEvent:
|
||||
class RawReactionClearEvent(_RawReprMixin):
|
||||
"""Represents the payload for a :func:`on_raw_reaction_clear` event.
|
||||
|
||||
Attributes
|
||||
|
Loading…
x
Reference in New Issue
Block a user