Browse Source

Change some format usage to use %-formatting.

Minor speed increase when we're not doing excessive attribute
access or any type of formatting.
pull/572/head
Rapptz 8 years ago
parent
commit
d24c2a09b6
  1. 2
      discord/abc.py
  2. 2
      discord/client.py
  3. 4
      discord/member.py
  4. 8
      discord/message.py
  5. 2
      discord/role.py

2
discord/abc.py

@ -194,7 +194,7 @@ class GuildChannel:
@property
def mention(self):
"""str : The string that allows you to mention the channel."""
return '<#{0.id}>'.format(self)
return '<#%s>' % self.id
@property
def created_at(self):

2
discord/client.py

@ -210,7 +210,7 @@ class Client:
pass
def dispatch(self, event, *args, **kwargs):
log.debug('Dispatching event {}'.format(event))
log.debug('Dispatching event %s', event)
method = 'on_' + event
handler = 'handle_' + event

4
discord/member.py

@ -249,8 +249,8 @@ class Member(discord.abc.Messageable):
def mention(self):
"""Returns a string that mentions the member."""
if self.nick:
return '<@!{}>'.format(self.id)
return '<@{}>'.format(self.id)
return '<@!%s>' % self.id
return '<@%s>' % self.id
@property
def display_name(self):

8
discord/message.py

@ -285,18 +285,18 @@ class Message:
"""
transformations = {
re.escape('<#{0.id}>'.format(channel)): '#' + channel.name
re.escape('<#%s>' % channel.id): '#' + channel.name
for channel in self.channel_mentions
}
mention_transforms = {
re.escape('<@{0.id}>'.format(member)): '@' + member.display_name
re.escape('<@%s>' % member.id): '@' + member.display_name
for member in self.mentions
}
# add the <@!user_id> cases as well..
second_mention_transforms = {
re.escape('<@!{0.id}>'.format(member)): '@' + member.display_name
re.escape('<@!%s>' % member.id): '@' + member.display_name
for member in self.mentions
}
@ -305,7 +305,7 @@ class Message:
if self.guild is not None:
role_transforms = {
re.escape('<@&{0.id}>'.format(role)): '@' + role.name
re.escape('<@&%s>' % role.id): '@' + role.name
for role in self.role_mentions
}
transformations.update(role_transforms)

2
discord/role.py

@ -148,7 +148,7 @@ class Role(Hashable):
@property
def mention(self):
"""Returns a string that allows you to mention a role."""
return '<@&{}>'.format(self.id)
return '<@&%s>' % self.id
@property
def members(self):

Loading…
Cancel
Save