|
@ -41,27 +41,27 @@ class PluginDeco(object): |
|
|
return deco |
|
|
return deco |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def listen(cls, event_name, priority=None): |
|
|
def listen(cls, *args, **kwargs): |
|
|
""" |
|
|
""" |
|
|
Binds the function to listen for a given event name |
|
|
Binds the function to listen for a given event name |
|
|
""" |
|
|
""" |
|
|
return cls.add_meta_deco({ |
|
|
return cls.add_meta_deco({ |
|
|
'type': 'listener', |
|
|
'type': 'listener', |
|
|
'what': 'event', |
|
|
'what': 'event', |
|
|
'desc': event_name, |
|
|
'args': args, |
|
|
'priority': priority |
|
|
'kwargs': kwargs, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def listen_packet(cls, op, priority=None): |
|
|
def listen_packet(cls, *args, **kwargs): |
|
|
""" |
|
|
""" |
|
|
Binds the function to listen for a given gateway op code |
|
|
Binds the function to listen for a given gateway op code |
|
|
""" |
|
|
""" |
|
|
return cls.add_meta_deco({ |
|
|
return cls.add_meta_deco({ |
|
|
'type': 'listener', |
|
|
'type': 'listener', |
|
|
'what': 'packet', |
|
|
'what': 'packet', |
|
|
'desc': op, |
|
|
'args': args, |
|
|
'priority': priority, |
|
|
'kwargs': kwargs, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
@ -187,7 +187,7 @@ class Plugin(LoggingClass, PluginDeco): |
|
|
|
|
|
|
|
|
def bind_meta(self, member, meta): |
|
|
def bind_meta(self, member, meta): |
|
|
if meta['type'] == 'listener': |
|
|
if meta['type'] == 'listener': |
|
|
self.register_listener(member, meta['what'], meta['desc'], meta['priority']) |
|
|
self.register_listener(member, meta['what'], *meta['args'], **meta['kwargs']) |
|
|
elif meta['type'] == 'command': |
|
|
elif meta['type'] == 'command': |
|
|
meta['kwargs']['update'] = True |
|
|
meta['kwargs']['update'] = True |
|
|
self.register_command(member, *meta['args'], **meta['kwargs']) |
|
|
self.register_command(member, *meta['args'], **meta['kwargs']) |
|
@ -248,7 +248,7 @@ class Plugin(LoggingClass, PluginDeco): |
|
|
|
|
|
|
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
def register_listener(self, func, what, desc, priority): |
|
|
def register_listener(self, func, what, desc, priority=Priority.NONE, conditional=None): |
|
|
""" |
|
|
""" |
|
|
Registers a listener |
|
|
Registers a listener |
|
|
|
|
|
|
|
@ -265,12 +265,10 @@ class Plugin(LoggingClass, PluginDeco): |
|
|
""" |
|
|
""" |
|
|
func = functools.partial(self._dispatch, 'listener', func) |
|
|
func = functools.partial(self._dispatch, 'listener', func) |
|
|
|
|
|
|
|
|
priority = priority or Priority.NONE |
|
|
|
|
|
|
|
|
|
|
|
if what == 'event': |
|
|
if what == 'event': |
|
|
li = self.bot.client.events.on(desc, func, priority=priority) |
|
|
li = self.bot.client.events.on(desc, func, priority=priority, conditional=conditional) |
|
|
elif what == 'packet': |
|
|
elif what == 'packet': |
|
|
li = self.bot.client.packets.on(desc, func, priority=priority) |
|
|
li = self.bot.client.packets.on(desc, func, priority=priority, conditional=conditional) |
|
|
else: |
|
|
else: |
|
|
raise Exception('Invalid listener what: {}'.format(what)) |
|
|
raise Exception('Invalid listener what: {}'.format(what)) |
|
|
|
|
|
|
|
|