Browse Source

Move to_snowflake to disco.util.snowflake

pull/5/head
Andrei 9 years ago
parent
commit
d8f5036b41
  1. 2
      disco/types/channel.py
  2. 2
      disco/types/guild.py
  3. 2
      disco/types/message.py
  4. 12
      disco/util/__init__.py
  5. 13
      disco/util/snowflake.py

2
disco/types/channel.py

@ -3,7 +3,7 @@ from holster.enum import Enum
from disco.types.base import Model, Field, snowflake, enum, listof, dictof, text from disco.types.base import Model, Field, snowflake, enum, listof, dictof, text
from disco.types.permissions import PermissionValue 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.util.functional import cached_property, one_or_many, chunks
from disco.types.user import User from disco.types.user import User
from disco.types.permissions import Permissions, Permissible from disco.types.permissions import Permissions, Permissible

2
disco/types/guild.py

@ -1,7 +1,7 @@
from holster.enum import Enum from holster.enum import Enum
from disco.api.http import APIException 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.util.functional import cached_property
from disco.types.base import Model, Field, snowflake, listof, dictof, datetime, text, binary, enum from disco.types.base import Model, Field, snowflake, listof, dictof, datetime, text, binary, enum
from disco.types.user import User from disco.types.user import User

2
disco/types/message.py

@ -3,7 +3,7 @@ import re
from holster.enum import Enum from holster.enum import Enum
from disco.types.base import Model, Field, snowflake, text, datetime, dictof, listof, 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.util.functional import cached_property
from disco.types.user import User from disco.types.user import User

12
disco/util/__init__.py

@ -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
disco/util/snowflake.py

@ -1,3 +1,5 @@
import six
from datetime import datetime from datetime import datetime
DISCORD_EPOCH = 1420070400000 DISCORD_EPOCH = 1420070400000
@ -16,3 +18,14 @@ def to_unix(snowflake):
def to_unix_ms(snowflake): def to_unix_ms(snowflake):
return ((int(snowflake) >> 22) + DISCORD_EPOCH) 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))

Loading…
Cancel
Save