aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-10-14 05:58:04 -0400
committerRapptz <[email protected]>2015-10-14 05:58:04 -0400
commit15b83b2743db632f1ec36377341f2100a8ce80bc (patch)
treef3fbdb15166bf877ee23bd670d183c7beee1ed97
parentVersion bump to v0.7.0 (diff)
downloaddiscord.py-15b83b2743db632f1ec36377341f2100a8ce80bc.tar.xz
discord.py-15b83b2743db632f1ec36377341f2100a8ce80bc.zip
Message.author is now either Member or User.
Closes #11.
-rw-r--r--discord/message.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/discord/message.py b/discord/message.py
index 01dbc37e..823085cd 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
-from .utils import parse_time
+from . import utils
from .user import User
class Message(object):
@@ -45,7 +45,8 @@ class Message(object):
Checks the message has text-to-speech support.
.. attribute:: author
- A :class:`User` that sent the message.
+ A :class:`Member` that sent the message. If :attr:`channel` is a private channel,
+ then it is a :class:`User` instead.
.. attribute:: content
The actual contents of the message.
@@ -74,8 +75,8 @@ class Message(object):
# we can use this to our advantage to use strptime instead of a complicated parsing routine.
# example timestamp: 2015-08-21T12:03:45.782000+00:00
# sometimes the .%f modifier is missing
- self.edited_timestamp = parse_time(kwargs.get('edited_timestamp'))
- self.timestamp = parse_time(kwargs.get('timestamp'))
+ self.edited_timestamp = utils.parse_time(kwargs.get('edited_timestamp'))
+ self.timestamp = utils.parse_time(kwargs.get('timestamp'))
self.tts = kwargs.get('tts')
self.content = kwargs.get('content')
self.mention_everyone = kwargs.get('mention_everyone')
@@ -85,4 +86,14 @@ class Message(object):
self.author = User(**kwargs.get('author', {}))
self.mentions = [User(**mention) for mention in kwargs.get('mentions', {})]
self.attachments = kwargs.get('attachments')
+ self._upgrade_to_member()
+
+ def _upgrade_to_member(self):
+ assert self.channel is not None
+
+ if not self.channel.is_private:
+ found = utils.find(lambda m: m.id == self.author.id, self.channel.server.members)
+ if found is not None:
+ self.author = found
+