Add util method to extract creation date from discord ids
This commit is contained in:
		| @@ -31,6 +31,7 @@ from base64 import b64encode | |||||||
| import asyncio | import asyncio | ||||||
| import json | import json | ||||||
|  |  | ||||||
|  | DISCORD_EPOCH = 1420070400000 | ||||||
|  |  | ||||||
| class cached_property: | class cached_property: | ||||||
|     def __init__(self, function): |     def __init__(self, function): | ||||||
| @@ -73,6 +74,12 @@ def parse_time(timestamp): | |||||||
|         return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', '')))) |         return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', '')))) | ||||||
|     return None |     return None | ||||||
|  |  | ||||||
|  | def snowflake_time(id): | ||||||
|  |     ''' | ||||||
|  |     Returns the creation date of a discord id. | ||||||
|  |     ''' | ||||||
|  |     return datetime.datetime.utcfromtimestamp(((int(id) >> 22) + DISCORD_EPOCH) / 1000) | ||||||
|  |  | ||||||
| def find(predicate, seq): | def find(predicate, seq): | ||||||
|     """A helper to return the first element found in the sequence |     """A helper to return the first element found in the sequence | ||||||
|     that meets the predicate. For example: :: |     that meets the predicate. For example: :: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user