Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Move to_snowflake to disco.util.snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
b1naryth1ef committed Oct 9, 2016
1 parent 6036dd8 commit d8f5036
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion disco/types/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from disco.types.base import Model, Field, snowflake, enum, listof, dictof, text
from disco.types.permissions import PermissionValue

from disco.util import to_snowflake
from disco.util.snowflake import to_snowflake
from disco.util.functional import cached_property, one_or_many, chunks
from disco.types.user import User
from disco.types.permissions import Permissions, Permissible
Expand Down
2 changes: 1 addition & 1 deletion disco/types/guild.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from holster.enum import Enum

from disco.api.http import APIException
from disco.util import to_snowflake
from disco.util.snowflake import to_snowflake
from disco.util.functional import cached_property
from disco.types.base import Model, Field, snowflake, listof, dictof, datetime, text, binary, enum
from disco.types.user import User
Expand Down
2 changes: 1 addition & 1 deletion disco/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from holster.enum import Enum

from disco.types.base import Model, Field, snowflake, text, datetime, dictof, listof, enum
from disco.util import to_snowflake
from disco.util.snowflake import to_snowflake
from disco.util.functional import cached_property
from disco.types.user import User

Expand Down
12 changes: 0 additions & 12 deletions disco/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
import six


def to_snowflake(i):
if isinstance(i, six.integer_types):
return i
elif isinstance(i, str):
return int(i)
elif hasattr(i, 'id'):
return i.id

raise Exception('{} ({}) is not convertable to a snowflake'.format(type(i), i))
13 changes: 13 additions & 0 deletions disco/util/snowflake.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import six

from datetime import datetime

DISCORD_EPOCH = 1420070400000
Expand All @@ -16,3 +18,14 @@ def to_unix(snowflake):

def to_unix_ms(snowflake):
return ((int(snowflake) >> 22) + DISCORD_EPOCH)


def to_snowflake(i):
if isinstance(i, six.integer_types):
return i
elif isinstance(i, str):
return int(i)
elif hasattr(i, 'id'):
return i.id

raise Exception('{} ({}) is not convertable to a snowflake'.format(type(i), i))

0 comments on commit d8f5036

Please sign in to comment.