pinhook/pinhook/plugin.py

50 lines
854 B
Python
Raw Normal View History

2018-03-15 19:04:58 +00:00
cmds = {}
lstnrs = {}
2017-09-27 21:55:00 +00:00
class Output:
def __init__(self, msg_type, msg):
self.msg_type = msg_type
self.msg = self.sanitize(msg)
def sanitize(self, msg):
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)
2018-03-15 19:04:58 +00:00
def _add_plugin(command, func):
cmds[command] = func
def _add_listener(name, func):
lstnrs[name] = func
2017-09-27 21:55:00 +00:00
def clear_plugins():
cmds.clear()
2017-12-06 19:05:57 +00:00
lstnrs.clear()
def register(command):
def register_for_command(func):
2018-03-15 19:04:58 +00:00
_add_plugin(command, func)
return func
return register_for_command
def listener(name):
def register_as_listener(func):
2018-03-15 19:04:58 +00:00
_add_listener(name, func)
return func
return register_as_listener