From 9330d4a8dd627c83874d789dce4e3e817dd9af8a Mon Sep 17 00:00:00 2001 From: andrei Date: Wed, 2 Nov 2016 17:33:37 -0700 Subject: [PATCH] Couple of fixes --- disco/bot/bot.py | 2 ++ disco/types/base.py | 19 ++++++++++--------- disco/types/user.py | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/disco/bot/bot.py b/disco/bot/bot.py index 369aea8..f5282ae 100644 --- a/disco/bot/bot.py +++ b/disco/bot/bot.py @@ -431,6 +431,8 @@ class Bot(object): for entry in map(lambda i: getattr(mod, i), dir(mod)): if inspect.isclass(entry) and issubclass(entry, Plugin) and not entry == Plugin: + if getattr(entry, '_shallow', False) and Plugin in entry.__bases__: + continue loaded = True self.add_plugin(entry, config) diff --git a/disco/types/base.py b/disco/types/base.py index 611672e..17fde2e 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -142,19 +142,20 @@ def enum(typ): return _f +# TODO: make lazy def lazy_datetime(data): if not data: - return property(lambda: None) + return None - def get(): - for fmt in DATETIME_FORMATS: - try: - return real_datetime.strptime(data.rsplit('+', 1)[0], fmt) - except (ValueError, TypeError): - continue - raise ValueError('Failed to conver `{}` to datetime'.format(data)) + if isinstance(data, int): + return real_datetime.utcfromtimestamp(data) - return property(get) + for fmt in DATETIME_FORMATS: + try: + return real_datetime.strptime(data.rsplit('+', 1)[0], fmt) + except (ValueError, TypeError): + continue + raise ValueError('Failed to conver `{}` to datetime'.format(data)) def datetime(data): diff --git a/disco/types/user.py b/disco/types/user.py index 15507d9..a860843 100644 --- a/disco/types/user.py +++ b/disco/types/user.py @@ -8,7 +8,7 @@ class User(SlottedModel, with_equality('id'), with_hash('id')): username = Field(text) avatar = Field(binary) discriminator = Field(str) - bot = Field(bool) + bot = Field(bool, default=False) verified = Field(bool) email = Field(str)