aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/__init__.py4
-rw-r--r--discord/client.py23
-rw-r--r--discord/message.py13
3 files changed, 25 insertions, 15 deletions
diff --git a/discord/__init__.py b/discord/__init__.py
index c8d0eb4f..9fccad0f 100644
--- a/discord/__init__.py
+++ b/discord/__init__.py
@@ -15,8 +15,8 @@ __title__ = 'discord'
__author__ = 'Rapptz'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015 Rapptz'
-__version__ = '0.2.0'
-__build__ = 0x002000
+__version__ = '0.2.1'
+__build__ = 0x002010
from client import Client
from user import User
diff --git a/discord/client.py b/discord/client.py
index 9fbfd178..eca91802 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
import requests
-import json, re, time
+import json, re, time, copy
import endpoints
from collections import deque
from threading import Timer
@@ -179,14 +179,21 @@ class Client(object):
elif event == 'MESSAGE_UPDATE':
older_message = self._get_message(data.get('id'))
if older_message is not None:
- message = Message(channel=older_message.channel, **data)
+ # create a copy of the new message
+ message = copy.deepcopy(older_message)
+ # update the new update
+ for attr in data:
+ if attr == 'channel_id':
+ continue
+ value = data[attr]
+ if 'time' in attr:
+ setattr(message, attr, message._parse_time(value))
+ else:
+ setattr(message, attr, value)
self._invoke_event('on_message_edit', older_message, message)
- older_message.edited_timestamp = message.edited_timestamp
- else:
- # if we couldn't find the message in our cache, just add it to the list
- channel = self.get_channel(data.get('channel_id'))
- message = Message(channel=channel, **data)
- self.messages.append(message)
+ # update the older message
+ older_message = message
+
elif event == 'PRESENCE_UPDATE':
guild_id = data.get('guild_id')
server = next((s for s in self.servers if s.id == guild_id), None)
diff --git a/discord/message.py b/discord/message.py
index 91140af1..0f7006cb 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -65,6 +65,9 @@ class Message(object):
.. attribute:: id
The message ID.
+ .. attribute:: attachments
+
+ An array of attachments given to a message.
"""
def __init__(self, edited_timestamp, timestamp, tts, content, mention_everyone, mentions, embeds, attachments, id, channel, author, **kwargs):
@@ -72,13 +75,11 @@ 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
- time_format = "%Y-%m-%dT%H:%M:%S.%f+00:00"
self.edited_timestamp = None
if edited_timestamp is not None:
- temp = edited_timestamp.replace('+00:00', '')
- self.edited_timestamp = datetime.datetime(*map(int, re.split(r'[^\d]', temp)))
+ self.edited_timestamp = self._parse_time(edited_timestamp)
- self.timestamp = datetime.datetime(*map(int, re.split(r'[^\d]', timestamp.replace('+00:00', ''))))
+ self.timestamp = self._parse_time(timestamp)
self.tts = tts
self.content = content
self.mention_everyone = mention_everyone
@@ -87,6 +88,8 @@ class Message(object):
self.channel = channel
self.author = User(**author)
self.mentions = [User(**mention) for mention in mentions]
+ self.attachments = attachments
-
+ def _parse_time(self, time_string):
+ return datetime.datetime(*map(int, re.split(r'[^\d]', time_string.replace('+00:00', ''))))