]>
jfr.im git - irc/rizon/acid.git/blob - pyva/pyva/src/main/python/control/control.py
1 from plugin
import AcidPlugin
2 from plugin
import modules
5 from istring
import istring
8 class control(AcidPlugin
):
10 AcidPlugin
.__init
__(self
)
12 self
.control
= config
.get('control', 'nick')
13 self
.controlchannel
= config
.get('control', 'channel')
15 def cmd_status(self
, source
, target
, pieces
):
18 las
= [str(x
)[:4] for x
in os
.getloadavg()]
20 las
= ["unk", "unk", "unk"]
22 self
.inter
.privmsg(self
.control
, target
, "Load: [%s %s %s]" % (las
[0], las
[1], las
[2]))
23 self
.inter
.privmsg(self
.control
, target
, "Modules loaded: %s" % (", ".join(self
.get_module_list())))
26 def cmd_help(self
, source
, target
, pieces
):
28 Prints a list of commands and syntax a user is allowed to use
29 TODO: change output to be more segregated:
30 `help` should list modules
31 `help <module>` should list help for that module
32 `help all` should list all commands
35 if len(pieces
) == 0 or len(pieces
) > 1:
36 self
.inter
.notice(self
.control
, source
, "Help is available for the following modules:")
37 self
.inter
.notice(self
.control
, source
, "help all")
38 for k
,v
in modules
.iteritems():
39 self
.inter
.notice(self
.control
, source
, "help %s" % v
.name
)
40 elif len(pieces
) == 1:
41 if pieces
[0] == "all":
47 for modname
in modules
:
48 mod
= modules
[modname
]
50 for name
,info
in mod
.getCommands():
51 cmds
.append([mod
.name
+ '.' + name
, info
])
53 user
= self
.inter
.findUser(source
)
54 for cmdname
,cmdinfo
in cmds
:
55 perm
= cmdinfo
['permission']
56 if not perm
or user
.hasFlags(perm
):
59 if not filter or filter == cmdname
.split('.')[0]:
60 self
.inter
.notice(self
.control
, source
, "[%s] %s%s %s" % (perm
, self
.prefix
, cmdname
, cmdinfo
['usage']))
62 self
.inter
.notice(self
.control
, source
, "End of Help")
65 def cmd_reload(self
, source
, target
, pieces
):
68 config
.read("config.ini")
69 self
.inter
.notice(self
.control
, source
, "Reloaded configuration")
71 except Exception, err
:
72 self
.log
.error("Error reloading config.ini (%s)" % err
)
75 def getCommands(self
):
79 'callback':self
.cmd_status
,
80 'usage':"- display technical information"}),
84 'callback':self
.cmd_help
,
85 'usage':"- shows help for all commands available *to you*"}),
89 'callback':self
.cmd_reload
,
90 'usage':"- reloads certain configuration parameters"}),
93 def onPrivmsg(self
, creator
, recipient
, message
):
94 params
= message
.split(' ')
95 user
= self
.inter
.findUser(creator
)
97 if not user
or len(params
) == 0 or len(params
[0]) == 0 or params
[0][0] != self
.prefix
or recipient
!= self
.controlchannel
:
102 for modname
in modules
:
103 mod
= modules
[modname
]
104 if not mod
.getCommands():
106 for cmdname
, info
in mod
.getCommands():
107 if mod
.name
+ '.' + cmdname
== cmd
and (not info
['permission'] or user
.hasFlags(info
['permission'])):
114 if not info
['callback'](creator
, recipient
, msg
):
115 self
.inter
.notice(self
.control
, creator
, "Usage: %s%s %s" % (self
.prefix
, cmd
, info
['usage']))
116 except Exception, err
:
117 self
.log
.error('COMMAND: Error executing %s (%s)' % (cmd
, err
))
119 traceback
.print_exc()