aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-04-05 18:01:24 -0400
committerRapptz <[email protected]>2016-04-05 18:01:55 -0400
commitdfd51b95d6ab3bcbe393c42194627df6c435dc4f (patch)
tree6f7d6d2b9b8f607c7a007f7db55d364453d54ac3
parentFix handling of message update in MESSAGE_UPDATE (diff)
downloaddiscord.py-dfd51b95d6ab3bcbe393c42194627df6c435dc4f.tar.xz
discord.py-dfd51b95d6ab3bcbe393c42194627df6c435dc4f.zip
Make Message.clean_content a cached property again.
Instead, clear the cached properties so they will be re-cached when invoked again.
-rw-r--r--discord/message.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/discord/message.py b/discord/message.py
index 3bd91a8e..c71a57d4 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -92,7 +92,7 @@ class Message:
__slots__ = [ 'edited_timestamp', 'timestamp', 'tts', 'content', 'channel',
'mention_everyone', 'embeds', 'id', 'mentions', 'author',
'channel_mentions', 'server', '_raw_mentions', 'attachments',
- 'clean_content', '_raw_channel_mentions', 'nonce' ]
+ '_clean_content', '_raw_channel_mentions', 'nonce' ]
def __init__(self, **kwargs):
self._update(**kwargs)
@@ -115,7 +115,11 @@ class Message:
self.attachments = data.get('attachments')
self._handle_upgrades(data.get('channel_id'))
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):
self.mentions = []
@@ -156,7 +160,8 @@ class Message:
"""
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"
manner. This basically means that mentions are transformed
into the way the client shows it. e.g. ``<#id>`` will transform