summaryrefslogtreecommitdiffstats
path: root/wmd/actions/modules.py
blob: c9e64501cb7c480395cb5a76e3f361906f6a6c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from wmd.actions import Action

import settings

class ReloadModule(Action):
    def recv_msg(self, irc, obj_data):
        username = obj_data.get_username()

        if username in settings.ADMINS:
            args = obj_data.params.split(" ")
            if "PRIVMSG" in obj_data.command and "RELOADMODULE" in args[1].upper():
                module = args[2]
                if not module in irc.actions:
                    irc.privmsg(username, "Invalid Module: %s")
                    return
                elif module == self.__class__.__name__:
                    irc.privmsg(username, "Unable to reload self. Try restarting")
                    return
                module_class = irc.actions[module].__module__
                module_path = module_class + '.' + module

                reload(irc.actions[module])

                msg = "Reloaded %s" % (module_path,)
                self.log(msg)
                irc.privmsg(username, msg)

class LoadModule(Action):
    def recv_msg(self, irc, obj_data):
        username = obj_data.get_username()
        if username in settings.ADMINS:
            args = obj_data.params.split(" ")
            if "PRIVMSG" in obj_data.command and ":LOADMODULE" in args[1].upper():
                module_path = args[2]
                if module_path.split(".")[-1] in irc.actions:
                    irc.privmsg(username, "Module %s already loaded" % (module_path,))
                    return
                #irc.load_action(module_path)

                msg = "Loading %s" % (module_path,)
                self.log(msg)
                irc.privmsg(username, msg)
                return {'load': module_path}

class ListModules(Action):
    def recv_msg(self, irc, obj_data):
        username = obj_data.get_username()

        if username in settings.ADMINS:
            args = obj_data.params.split(" ")
            if "PRIVMSG" in obj_data.command and ":LISTMODULES" in args[1].upper():
                for module in irc.actions:
                    msg = module
                    irc.privmsg(username, msg)

class UnloadModule(Action):
    def recv_msg(self, irc, obj_data):
        username = obj_data.get_username()

        if username in settings.ADMINS:
            args = obj_data.params.split(" ")
            if "PRIVMSG" in obj_data.command and ":UNLOADMODULE" in args[1].upper():
                module_name = args[2]
                if not module_name in irc.actions:
                    irc.privmsg(username, "Module %s already unloaded" % (module_name,))
                    return
                    #irc.load_action(module_path)

                msg = "Unloading %s" % (module_name,)
                self.log(msg)
                irc.privmsg(username, msg)
                return {'unload': module_name}