Browse Source

Make Message.clean_content a cached property again.

Instead, clear the cached properties so they will be re-cached when
invoked again.
pull/140/merge
Rapptz 9 years ago
parent
commit
dfd51b95d6
  1. 11
      discord/message.py

11
discord/message.py

@ -92,7 +92,7 @@ class Message:
__slots__ = [ 'edited_timestamp', 'timestamp', 'tts', 'content', 'channel', __slots__ = [ 'edited_timestamp', 'timestamp', 'tts', 'content', 'channel',
'mention_everyone', 'embeds', 'id', 'mentions', 'author', 'mention_everyone', 'embeds', 'id', 'mentions', 'author',
'channel_mentions', 'server', '_raw_mentions', 'attachments', 'channel_mentions', 'server', '_raw_mentions', 'attachments',
'clean_content', '_raw_channel_mentions', 'nonce' ] '_clean_content', '_raw_channel_mentions', 'nonce' ]
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._update(**kwargs) self._update(**kwargs)
@ -115,7 +115,11 @@ class Message:
self.attachments = data.get('attachments') self.attachments = data.get('attachments')
self._handle_upgrades(data.get('channel_id')) self._handle_upgrades(data.get('channel_id'))
self._handle_mentions(data.get('mentions', [])) self._handle_mentions(data.get('mentions', []))
self.clean_content = self._clean_content()
# clear the cached slot cache
del self._raw_mentions
del self._raw_channel_mentions
del self._clean_content
def _handle_mentions(self, mentions): def _handle_mentions(self, mentions):
self.mentions = [] self.mentions = []
@ -156,7 +160,8 @@ class Message:
""" """
return re.findall(r'<#([0-9]+)>', self.content) return re.findall(r'<#([0-9]+)>', self.content)
def _clean_content(self): @utils.cached_slot_property('_clean_content')
def clean_content(self):
"""A property that returns the content in a "cleaned up" """A property that returns the content in a "cleaned up"
manner. This basically means that mentions are transformed manner. This basically means that mentions are transformed
into the way the client shows it. e.g. ``<#id>`` will transform into the way the client shows it. e.g. ``<#id>`` will transform

Loading…
Cancel
Save