aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorslice <[email protected]>2019-02-15 23:19:45 -0800
committerslice <[email protected]>2019-02-15 23:20:06 -0800
commitcfc2e47b4f25bde3ed21365b6507f023b7b39977 (patch)
tree7de9cadd2eeafd1d14e750d7b5fbd3944470e5cd
parentFix system_content returning incorrect join messages (diff)
downloaddiscord.py-cfc2e47b4f25bde3ed21365b6507f023b7b39977.tar.xz
discord.py-cfc2e47b4f25bde3ed21365b6507f023b7b39977.zip
Manually calculate millisceond epoch rather than bitshifting
Implementation by Danny.
-rw-r--r--discord/message.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/discord/message.py b/discord/message.py
index 74b09624..2a41c2fa 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
import asyncio
+import datetime
import re
from . import utils
@@ -514,10 +515,11 @@ class Message:
"Roses are red, violets are blue, {0} joined this server with you",
]
- # we can't use snowflake_time here because we need the millisecond
- # precision from snowflakes in order to calculate the correct format
- index = ((self.id >> 22) + utils.DISCORD_EPOCH) % len(formats)
- return formats[index].format(self.author.name)
+ # manually reconstruct the epoch with millisecond precision, because
+ # datetime.datetime.timestamp() doesn't return the exact posix
+ # timestamp with the precision that we need
+ created_at_ms = int((self.created_at - datetime.datetime(1970, 1, 1)).total_seconds() * 1000)
+ return formats[created_at_ms % len(formats)].format(self.author.name)
if self.type is MessageType.call:
# we're at the call message type now, which is a bit more complicated.