diff options
| author | jason | 2012-07-21 16:20:21 -0600 |
|---|---|---|
| committer | jason | 2012-07-21 16:20:21 -0600 |
| commit | ecf83c6b4576138d34ee3056db997a66476a3f29 (patch) | |
| tree | 48486ae033e4515cd1144d1ef0a9a433ddbb3b40 /wmd/irc.py | |
| parent | 95413bf63d54eb08ce4fb2dc972559f36551b195 (diff) | |
| download | warmachine-ecf83c6b4576138d34ee3056db997a66476a3f29.tar.gz warmachine-ecf83c6b4576138d34ee3056db997a66476a3f29.zip | |
Added support to dynamically load modules.
Diffstat (limited to 'wmd/irc.py')
| -rw-r--r-- | wmd/irc.py | 24 |
1 files changed, 17 insertions, 7 deletions
| @@ -14,7 +14,7 @@ class IRC(object): | |||
| 14 | self.nick = nick | 14 | self.nick = nick |
| 15 | self.name = name | 15 | self.name = name |
| 16 | self.port = port | 16 | self.port = port |
| 17 | self.actions = [] | 17 | self.actions = dict() |
| 18 | 18 | ||
| 19 | self.load_actions() | 19 | self.load_actions() |
| 20 | 20 | ||
| @@ -66,7 +66,7 @@ class IRC(object): | |||
| 66 | module_name, class_name = path.rsplit('.', 1) | 66 | module_name, class_name = path.rsplit('.', 1) |
| 67 | module = __import__(module_name, globals(), locals(), [class_name], -1) | 67 | module = __import__(module_name, globals(), locals(), [class_name], -1) |
| 68 | classz = getattr(module, class_name) | 68 | classz = getattr(module, class_name) |
| 69 | self.actions.insert(0, classz()) | 69 | self.actions[class_name] = classz() |
| 70 | 70 | ||
| 71 | def __call__(self, *args, **kwargs): | 71 | def __call__(self, *args, **kwargs): |
| 72 | """ | 72 | """ |
| @@ -82,14 +82,24 @@ class IRC(object): | |||
| 82 | if data[-1] != '\n': | 82 | if data[-1] != '\n': |
| 83 | data = data + self.irc.recv(4096) | 83 | data = data + self.irc.recv(4096) |
| 84 | 84 | ||
| 85 | # For dynamic loading, we have to add to the actions dictionary after we're through looping. Maybe there | ||
| 86 | # are some other cases to use the post_loop_commands | ||
| 85 | for line in data.split('\r\n'): | 87 | for line in data.split('\r\n'): |
| 86 | obj_data = parser.IRCParse(line) | 88 | obj_data = parser.IRCParse(line) |
| 87 | #pass to action handlers here... | 89 | #pass to action handlers here... |
| 88 | if (obj_data.prefix == '') and (obj_data.command == '') and (obj_data.params == ''): | 90 | if (obj_data.prefix == '') and (obj_data.command == '') and (obj_data.params == ''): |
| 89 | continue | 91 | continue |
| 90 | 92 | ||
| 91 | print "!" + obj_data.prefix + "~" + obj_data.command + "~" + obj_data.params | 93 | print "<- " + obj_data.prefix + "~" + obj_data.command + "~" + obj_data.params |
| 92 | for action in self.actions: | 94 | |
| 93 | retval = action.recv_msg(self, obj_data) | 95 | modules_to_load = [] |
| 94 | if retval: | 96 | for plugin_name in self.actions: |
| 95 | self.rawsend(retval) \ No newline at end of file | 97 | retval = self.actions[plugin_name].recv_msg(self, obj_data) |
| 98 | if type(retval) == type(dict()): | ||
| 99 | if retval.has_key('load'): | ||
| 100 | modules_to_load.append(retval['load']) | ||
| 101 | elif type(retval) == type('str is str'): | ||
| 102 | self.rawsend(retval) | ||
| 103 | |||
| 104 | for module in modules_to_load: | ||
| 105 | self.load_action(module) | ||