summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--settings.py2
-rw-r--r--wmd/actions/modules.py24
-rw-r--r--wmd/irc.py13
3 files changed, 35 insertions, 4 deletions
diff --git a/settings.py b/settings.py
index d6c22a9..32200da 100644
--- a/settings.py
+++ b/settings.py
@@ -21,6 +21,8 @@ ACTIONS = (
21 'wmd.actions.modules.ReloadModule', 21 'wmd.actions.modules.ReloadModule',
22 'wmd.actions.modules.LoadModule', 22 'wmd.actions.modules.LoadModule',
23 'wmd.actions.modules.ListModules', 23 'wmd.actions.modules.ListModules',
24 'wmd.actions.modules.UnloadModule',
25
24) 26)
25 27
26try: 28try:
diff --git a/wmd/actions/modules.py b/wmd/actions/modules.py
index 60a1436..eb726c2 100644
--- a/wmd/actions/modules.py
+++ b/wmd/actions/modules.py
@@ -32,9 +32,9 @@ class LoadModule(Action):
32 32
33 if username in settings.ADMINS: 33 if username in settings.ADMINS:
34 args = obj_data.params.split(" ") 34 args = obj_data.params.split(" ")
35 if "PRIVMSG" in obj_data.command and "LOADMODULE" in args[1].upper(): 35 if "PRIVMSG" in obj_data.command and ":LOADMODULE" in args[1].upper():
36 module_path = args[2] 36 module_path = args[2]
37 if module_path in irc.actions: 37 if module_path.split(".")[-1] in irc.actions:
38 irc.privmsg(username, "Module %s already loaded" % (module_path,)) 38 irc.privmsg(username, "Module %s already loaded" % (module_path,))
39 return 39 return
40 #irc.load_action(module_path) 40 #irc.load_action(module_path)
@@ -50,7 +50,25 @@ class ListModules(Action):
50 50
51 if username in settings.ADMINS: 51 if username in settings.ADMINS:
52 args = obj_data.params.split(" ") 52 args = obj_data.params.split(" ")
53 if "PRIVMSG" in obj_data.command and "LISTMODULES" in args[1].upper(): 53 if "PRIVMSG" in obj_data.command and ":LISTMODULES" in args[1].upper():
54 for module in irc.actions: 54 for module in irc.actions:
55 msg = module 55 msg = module
56 irc.privmsg(username, msg) 56 irc.privmsg(username, msg)
57
58class UnloadModule(Action):
59 def recv_msg(self, irc, obj_data):
60 username = obj_data.get_username()
61
62 if username in settings.ADMINS:
63 args = obj_data.params.split(" ")
64 if "PRIVMSG" in obj_data.command and ":UNLOADMODULE" in args[1].upper():
65 module_name = args[2]
66 if not module_name in irc.actions:
67 irc.privmsg(username, "Module %s already unloaded" % (module_name,))
68 return
69 #irc.load_action(module_path)
70
71 msg = "Unloading %s" % (module_name,)
72 self.log(msg)
73 irc.privmsg(username, msg)
74 return {'unload': module_name} \ No newline at end of file
diff --git a/wmd/irc.py b/wmd/irc.py
index dd99f5c..813f743 100644
--- a/wmd/irc.py
+++ b/wmd/irc.py
@@ -64,7 +64,12 @@ class IRC(object):
64 Loads the provided action 64 Loads the provided action
65 """ 65 """
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 try:
68 module = __import__(module_name, globals(), locals(), [class_name], -1)
69 except ImportError:
70 self.log("Error loading module: %s" %(path,))
71 return
72
68 classz = getattr(module, class_name) 73 classz = getattr(module, class_name)
69 self.actions[class_name] = classz() 74 self.actions[class_name] = classz()
70 75
@@ -93,13 +98,19 @@ class IRC(object):
93 print "<- " + obj_data.prefix + "~" + obj_data.command + "~" + obj_data.params 98 print "<- " + obj_data.prefix + "~" + obj_data.command + "~" + obj_data.params
94 99
95 modules_to_load = [] 100 modules_to_load = []
101 modules_to_unload = []
96 for plugin_name in self.actions: 102 for plugin_name in self.actions:
97 retval = self.actions[plugin_name].recv_msg(self, obj_data) 103 retval = self.actions[plugin_name].recv_msg(self, obj_data)
98 if type(retval) == type(dict()): 104 if type(retval) == type(dict()):
99 if retval.has_key('load'): 105 if retval.has_key('load'):
100 modules_to_load.append(retval['load']) 106 modules_to_load.append(retval['load'])
107 if retval.has_key('unload'):
108 modules_to_unload.append(retval['unload'])
101 elif type(retval) == type('str is str'): 109 elif type(retval) == type('str is str'):
102 self.rawsend(retval) 110 self.rawsend(retval)
103 111
104 for module in modules_to_load: 112 for module in modules_to_load:
105 self.load_action(module) 113 self.load_action(module)
114 for module in modules_to_unload:
115 if self.actions.has_key(module):
116 del(self.actions[module])