diff --git a/disco/api/client.py b/disco/api/client.py index eb6527a..6e5c40d 100644 --- a/disco/api/client.py +++ b/disco/api/client.py @@ -9,10 +9,20 @@ from disco.types.invite import Invite def optional(**kwargs): + """ + Takes a set of keyword arguments, creating a dictionary with only the non- + null values. + + :returns: dict + """ return {k: v for k, v in kwargs.items() if v is not None} class APIClient(LoggingClass): + """ + An abstraction over the :class:`HTTPClient` that composes requests, and fits + the models with the returned data. + """ def __init__(self, client): super(APIClient, self).__init__() diff --git a/disco/api/ratelimit.py b/disco/api/ratelimit.py index d0acc25..80ed940 100644 --- a/disco/api/ratelimit.py +++ b/disco/api/ratelimit.py @@ -47,17 +47,23 @@ class RateLimiter(object): self.states = {} def check(self, route, timeout=None): + return self._check(None, timeout) and self._check(route, timeout) + + def _check(self, route, timeout=None): if route in self.states: # If we're current waiting, join the club if self.states[route].chilled: return self.states[route].wait(timeout) if self.states[route].next_will_ratelimit(): - self.states[route].cooldown() + gevent.spawn(self.states[route].cooldown).wait(timeout) return True def update(self, route, request): + if 'X-RateLimit-Global' in request.headers: + route = None + if route in self.states: self.states[route].update(request) else: diff --git a/disco/bot/plugin.py b/disco/bot/plugin.py index cbd5c2c..26eb04d 100644 --- a/disco/bot/plugin.py +++ b/disco/bot/plugin.py @@ -112,7 +112,7 @@ class Plugin(LoggingClass, PluginDeco): def register_command(self, func, *args, **kwargs): wrapped = functools.partial(self._dispatch, 'command', func) - self.commands[func.__name__] = Command(self, func, *args, **kwargs) + self.commands[func.__name__] = Command(self, wrapped, *args, **kwargs) def destroy(self): map(lambda k: k.remove(), self._events) diff --git a/disco/gateway/events.py b/disco/gateway/events.py index 2aac7bc..4050d8e 100644 --- a/disco/gateway/events.py +++ b/disco/gateway/events.py @@ -5,6 +5,7 @@ from disco.util import skema_find_recursive_by_type from disco.types import Guild, Channel, User, GuildMember, Role, Message, VoiceState +# TODO: clean this... use BaseType, etc class GatewayEvent(skema.Model): @staticmethod def from_dispatch(client, data): diff --git a/disco/types/base.py b/disco/types/base.py index 96e8588..2f9c41c 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -19,8 +19,8 @@ class BaseType(skema.Model): # Valdiate obj.validate() - for item in skema_find_recursive_by_type(obj, skema.ModelType): - item.client = client + for field, value in skema_find_recursive_by_type(obj, skema.ModelType): + value.client = client obj.client = client return obj