aboutsummaryrefslogtreecommitdiff
path: root/discord/message.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-01-03 08:41:44 -0500
committerRapptz <[email protected]>2017-01-03 09:52:10 -0500
commit98b981848d757e8fb66d4a874a3107c0e8de2963 (patch)
treef0969e87a7835b6b253fa1f47381ba4045b1ae2a /discord/message.py
parentMove away from StateContext and use ConnectionState directly. (diff)
downloaddiscord.py-98b981848d757e8fb66d4a874a3107c0e8de2963.tar.xz
discord.py-98b981848d757e8fb66d4a874a3107c0e8de2963.zip
Move message creation to a factory method inside ConnectionState.
Diffstat (limited to 'discord/message.py')
-rw-r--r--discord/message.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/discord/message.py b/discord/message.py
index 308d5366..4854c23b 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -27,8 +27,9 @@ DEALINGS IN THE SOFTWARE.
import asyncio
import re
-import discord.utils
import discord.abc
+
+from . import utils
from .user import User
from .reaction import Reaction
from .emoji import Emoji
@@ -136,7 +137,7 @@ class Message:
def _add_reaction(self, data):
emoji = self._state.get_reaction_emoji(data['emoji'])
- reaction = discord.utils.find(lambda r: r.emoji == emoji, self.reactions)
+ reaction = utils.find(lambda r: r.emoji == emoji, self.reactions)
is_me = data['me'] = int(data['user_id']) == self._state.self_id
if reaction is None:
@@ -151,7 +152,7 @@ class Message:
def _remove_reaction(self, data):
emoji = self._state.get_reaction_emoji(data['emoji'])
- reaction = discord.utils.find(lambda r: r.emoji == emoji, self.reactions)
+ reaction = utils.find(lambda r: r.emoji == emoji, self.reactions)
if reaction is None:
# already removed?
@@ -177,7 +178,7 @@ class Message:
except KeyError:
continue
- self._try_patch(data, 'edited_timestamp', discord.utils.parse_time)
+ self._try_patch(data, 'edited_timestamp', utils.parse_time)
self._try_patch(data, 'pinned', bool)
self._try_patch(data, 'mention_everyone', bool)
self._try_patch(data, 'tts', bool)
@@ -218,7 +219,7 @@ class Message:
self.role_mentions = []
if self.guild is not None:
for role_id in role_mentions:
- role = discord.utils.get(self.guild.roles, id=role_id)
+ role = utils.get(self.guild.roles, id=role_id)
if role is not None:
self.role_mentions.append(role)
@@ -235,19 +236,19 @@ class Message:
if uid == self.author.id:
participants.append(self.author)
else:
- user = discord.utils.find(lambda u: u.id == uid, self.mentions)
+ user = utils.find(lambda u: u.id == uid, self.mentions)
if user is not None:
participants.append(user)
call['participants'] = participants
self.call = CallMessage(message=self, **call)
- @discord.utils.cached_slot_property('_cs_guild')
+ @utils.cached_slot_property('_cs_guild')
def guild(self):
"""Optional[:class:`Guild`]: The guild that the message belongs to, if applicable."""
return getattr(self.channel, 'guild', None)
- @discord.utils.cached_slot_property('_cs_raw_mentions')
+ @utils.cached_slot_property('_cs_raw_mentions')
def raw_mentions(self):
"""A property that returns an array of user IDs matched with
the syntax of <@user_id> in the message content.
@@ -257,28 +258,28 @@ class Message:
"""
return [int(x) for x in re.findall(r'<@!?([0-9]+)>', self.content)]
- @discord.utils.cached_slot_property('_cs_raw_channel_mentions')
+ @utils.cached_slot_property('_cs_raw_channel_mentions')
def raw_channel_mentions(self):
"""A property that returns an array of channel IDs matched with
the syntax of <#channel_id> in the message content.
"""
return [int(x) for x in re.findall(r'<#([0-9]+)>', self.content)]
- @discord.utils.cached_slot_property('_cs_raw_role_mentions')
+ @utils.cached_slot_property('_cs_raw_role_mentions')
def raw_role_mentions(self):
"""A property that returns an array of role IDs matched with
the syntax of <@&role_id> in the message content.
"""
return [int(x) for x in re.findall(r'<@&([0-9]+)>', self.content)]
- @discord.utils.cached_slot_property('_cs_channel_mentions')
+ @utils.cached_slot_property('_cs_channel_mentions')
def channel_mentions(self):
if self.guild is None:
return []
it = filter(None, map(lambda m: self.guild.get_channel(m), self.raw_channel_mentions))
- return discord.utils._unique(it)
+ return utils._unique(it)
- @discord.utils.cached_slot_property('_cs_clean_content')
+ @utils.cached_slot_property('_cs_clean_content')
def clean_content(self):
"""A property that returns the content in a "cleaned up"
manner. This basically means that mentions are transformed
@@ -352,9 +353,9 @@ class Message:
@property
def created_at(self):
"""Returns the message's creation time in UTC."""
- return discord.utils.snowflake_time(self.id)
+ return utils.snowflake_time(self.id)
- @discord.utils.cached_slot_property('_cs_system_content')
+ @utils.cached_slot_property('_cs_system_content')
def system_content(self):
"""A property that returns the content that is rendered
regardless of the :attr:`Message.type`.