diff options
| author | Rapptz <[email protected]> | 2016-10-10 20:09:06 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-03 09:51:49 -0500 |
| commit | 45c729b167509deb5e389a7812d0ae8f4cbc4e72 (patch) | |
| tree | 5617af109edb3d7b7fb0e28934bf57e4f664f362 /discord/utils.py | |
| parent | Remove Message.timestamp and make Message.channel_mentions lazy. (diff) | |
| download | discord.py-45c729b167509deb5e389a7812d0ae8f4cbc4e72.tar.xz discord.py-45c729b167509deb5e389a7812d0ae8f4cbc4e72.zip | |
Switch IDs to use int instead of str
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/discord/utils.py b/discord/utils.py index 83129654..5b19c8c3 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -120,7 +120,7 @@ def oauth_url(client_id, permissions=None, server=None, redirect_uri=None): def snowflake_time(id): """Returns the creation date in UTC of a discord id.""" - return datetime.datetime.utcfromtimestamp(((int(id) >> 22) + DISCORD_EPOCH) / 1000) + return datetime.datetime.utcfromtimestamp(((id >> 22) + DISCORD_EPOCH) / 1000) def time_snowflake(datetime_obj, high=False): """Returns a numeric snowflake pretending to be created at the given date. @@ -231,8 +231,15 @@ def _unique(iterable): adder = seen.add return [x for x in iterable if not (x in seen or adder(x))] -def _null_event(*args, **kwargs): - pass +def _get_as_snowflake(data, key): + try: + value = data[key] + except KeyError: + return None + else: + if value is None: + return value + return int(value) def _get_mime_type_for_image(data): if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'): |