diff --git a/disco/bot/bot.py b/disco/bot/bot.py index f5282ae..428f76a 100644 --- a/disco/bot/bot.py +++ b/disco/bot/bot.py @@ -383,9 +383,10 @@ class Bot(object): else: config = self.load_plugin_config(cls) - self.plugins[cls.__name__] = cls(self, config) + self.ctx['plugin'] = self.plugins[cls.__name__] = cls(self, config) self.plugins[cls.__name__].load(ctx or {}) self.recompute() + self.ctx.drop() def rmv_plugin(self, cls): """ diff --git a/disco/bot/command.py b/disco/bot/command.py index 5843046..5ef873f 100644 --- a/disco/bot/command.py +++ b/disco/bot/command.py @@ -113,10 +113,11 @@ class Command(object): self.group = None self.is_regex = None self.oob = False + self.context = {} self.update(*args, **kwargs) - def update(self, args=None, level=None, aliases=None, group=None, is_regex=None, oob=False): + def update(self, args=None, level=None, aliases=None, group=None, is_regex=None, oob=False, context=None): self.triggers += aliases or [] def resolve_role(ctx, rid): @@ -135,6 +136,7 @@ class Command(object): self.group = group self.is_regex = is_regex self.oob = oob + self.context = context or {} @staticmethod def mention_type(getters, force=False): @@ -201,4 +203,4 @@ class Command(object): except ArgumentError as e: raise CommandError(e.message) - return self.func(event, *args) + return self.func(event, *args, **self.context) diff --git a/disco/bot/plugin.py b/disco/bot/plugin.py index 10044c1..3764f38 100644 --- a/disco/bot/plugin.py +++ b/disco/bot/plugin.py @@ -256,7 +256,7 @@ class Plugin(LoggingClass, PluginDeco): return True - def register_listener(self, func, what, desc, **kwargs): + def register_listener(self, func, what, *args, **kwargs): """ Registers a listener. @@ -269,12 +269,12 @@ class Plugin(LoggingClass, PluginDeco): desc The descriptor of the event/packet. """ - func = functools.partial(self._dispatch, 'listener', func) + args = list(args) + [functools.partial(self._dispatch, 'listener', func)] if what == 'event': - li = self.bot.client.events.on(desc, func, **kwargs) + li = self.bot.client.events.on(*args, **kwargs) elif what == 'packet': - li = self.bot.client.packets.on(desc, func, **kwargs) + li = self.bot.client.packets.on(*args, **kwargs) else: raise Exception('Invalid listener what: {}'.format(what)) @@ -294,11 +294,13 @@ class Plugin(LoggingClass, PluginDeco): Keyword arguments to pass onto the :class:`disco.bot.command.Command` object. """ - if kwargs.pop('update', False) and func.__name__ in self.commands: - self.commands[func.__name__].update(*args, **kwargs) + name = args[0] + + if kwargs.pop('update', False) and name in self.commands: + self.commands[name].update(*args, **kwargs) else: wrapped = functools.partial(self._dispatch, 'command', func) - self.commands[func.__name__] = Command(self, wrapped, *args, **kwargs) + self.commands[name] = Command(self, wrapped, *args, **kwargs) def register_schedule(self, func, interval, repeat=True, init=True): """ diff --git a/disco/bot/providers/redis.py b/disco/bot/providers/redis.py index 1e5150a..f5e1375 100644 --- a/disco/bot/providers/redis.py +++ b/disco/bot/providers/redis.py @@ -31,6 +31,10 @@ class RedisProvider(BaseProvider): yield key def get_many(self, keys): + keys = list(keys) + if not len(keys): + raise StopIteration + for key, value in izip(keys, self.conn.mget(keys)): yield (key, Serializer.loads(self.format, value)) diff --git a/disco/gateway/events.py b/disco/gateway/events.py index 6799795..3e8af68 100644 --- a/disco/gateway/events.py +++ b/disco/gateway/events.py @@ -591,6 +591,14 @@ class MessageReactionAdd(GatewayEvent): user_id = Field(snowflake) emoji = Field(MessageReactionEmoji) + @property + def channel(self): + return self.client.state.channels.get(self.channel_id) + + @property + def guild(self): + return self.channel.guild + class MessageReactionRemove(GatewayEvent): """ @@ -611,3 +619,11 @@ class MessageReactionRemove(GatewayEvent): message_id = Field(snowflake) user_id = Field(snowflake) emoji = Field(MessageReactionEmoji) + + @property + def channel(self): + return self.client.state.channels.get(self.channel_id) + + @property + def guild(self): + return self.channel.guild diff --git a/disco/types/message.py b/disco/types/message.py index 14115ef..b5eaf17 100644 --- a/disco/types/message.py +++ b/disco/types/message.py @@ -371,7 +371,8 @@ class MessageTable(object): self.recalculate_size_index(args) def add(self, *args): - args = list(map(str, args)) + convert = lambda v: v if isinstance(v, basestring) else str(v) + args = list(map(convert, args)) self.entries.append(args) self.recalculate_size_index(args) diff --git a/disco/types/permissions.py b/disco/types/permissions.py index 7afb3f7..ff43145 100644 --- a/disco/types/permissions.py +++ b/disco/types/permissions.py @@ -76,13 +76,13 @@ class PermissionValue(object): return self.sub(other) def __getattribute__(self, name): - if name in Permissions.attrs: + if name in Permissions.keys_: return (self.value & Permissions[name].value) == Permissions[name].value else: return object.__getattribute__(self, name) def __setattr__(self, name, value): - if name not in Permissions.attrs: + if name not in Permissions.keys_: return super(PermissionValue, self).__setattr__(name, value) if value: