2017-09-27 21:55:00 +00:00
|
|
|
cmds = []
|
2017-12-06 18:45:34 +00:00
|
|
|
lstnrs = []
|
|
|
|
|
2017-09-27 21:55:00 +00:00
|
|
|
|
|
|
|
class Output:
|
|
|
|
def __init__(self, msg_type, msg):
|
|
|
|
self.msg_type = msg_type
|
2017-11-27 05:10:40 +00:00
|
|
|
self.msg = self.sanitize(msg)
|
|
|
|
|
|
|
|
def sanitize(self, msg):
|
2017-12-06 18:45:34 +00:00
|
|
|
try:
|
|
|
|
return msg.splitlines()
|
|
|
|
except AttributeError:
|
|
|
|
return msg
|
2017-09-27 21:55:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def action(msg):
|
|
|
|
return Output('action', msg)
|
|
|
|
|
|
|
|
|
|
|
|
def message(msg):
|
|
|
|
return Output('message', msg)
|
|
|
|
|
|
|
|
|
|
|
|
def add_plugin(command, func):
|
|
|
|
cmds.append({'cmd': command, 'func': func})
|
|
|
|
|
2017-09-27 23:54:08 +00:00
|
|
|
|
2017-11-30 11:12:33 +00:00
|
|
|
def clear_plugins():
|
|
|
|
cmds.clear()
|
|
|
|
|
|
|
|
|
2017-12-06 18:45:34 +00:00
|
|
|
def add_listener(name, func):
|
|
|
|
lstnrs.append({'lstn': name, 'func': func})
|
|
|
|
|
|
|
|
|
2017-09-27 23:54:08 +00:00
|
|
|
def register(command):
|
|
|
|
def register_for_command(func):
|
|
|
|
add_plugin(command, func)
|
|
|
|
return func
|
|
|
|
return register_for_command
|
|
|
|
|
2017-12-06 18:45:34 +00:00
|
|
|
|
|
|
|
def listener(name):
|
|
|
|
def register_as_listener(func):
|
|
|
|
add_listener(name, func)
|
|
|
|
return func
|
|
|
|
return register_as_listener
|