mirror of https://github.com/Mikaela/Limnoria.git
setconf can now list conf variables and tell which type they are.
This commit is contained in:
parent
776bad5700
commit
1b1fe4408e
|
@ -115,11 +115,14 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg):
|
|||
irc.error(msg, conf.replyEvalNotAllowed)
|
||||
|
||||
def setconf(self, irc, msg, args):
|
||||
"""<name> <value>
|
||||
"""[<name> [<value>]]
|
||||
|
||||
Sets the value of the conf-module variable <name> to <value>.
|
||||
Lists adjustable variables in the conf-module by default, shows the
|
||||
variable type with only the <name> argument and sets the value of the
|
||||
variable to <value> when both arguments are given.
|
||||
"""
|
||||
(name, value) = privmsgs.getArgs(args, needed=2)
|
||||
(name, value) = privmsgs.getArgs(args, needed=0, optional=2)
|
||||
if name and value:
|
||||
if conf.allowEval:
|
||||
try:
|
||||
value = eval(value)
|
||||
|
@ -144,6 +147,39 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg):
|
|||
return
|
||||
setattr(conf, name, value)
|
||||
irc.reply(msg, conf.replySuccess)
|
||||
elif name:
|
||||
typetable = {'mystr': 'string',
|
||||
'mybool': 'boolean',
|
||||
'float': 'float'}
|
||||
|
||||
try:
|
||||
vtype = conf.types[name].__name__
|
||||
except KeyError:
|
||||
irc.error(msg, 'That conf variable doesn\'t exist.')
|
||||
return
|
||||
try:
|
||||
irc.reply(msg, '%s is a %s.' % (name, typetable[vtype]))
|
||||
except KeyError:
|
||||
irc.error(msg, '%s is of an unknown type.' % name)
|
||||
else:
|
||||
options = conf.types.keys()
|
||||
options.sort()
|
||||
irc.reply(msg, ', '.join(options))
|
||||
|
||||
def listconf(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
||||
Lists the variables in conf-module that can be adjusted with setconf.
|
||||
"""
|
||||
options = []
|
||||
for key in conf.types.keys():
|
||||
otype = conf.types[key].__name__
|
||||
if otype[:2] == 'my':
|
||||
otype = otype[2:]
|
||||
options.append('%s (%s)' % (key, otype))
|
||||
|
||||
options.sort()
|
||||
irc.reply(msg, ', '.join(options))
|
||||
|
||||
def setdefaultcapability(self, irc, msg, args):
|
||||
"""<capability>
|
||||
|
|
|
@ -98,6 +98,11 @@ class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
|||
self.assertError('unload MiscCommands')
|
||||
|
||||
def testSetconf(self):
|
||||
self.assertRegexp('setconf', 'confDir')
|
||||
self.assertNotRegexp('setconf', 'allowEval')
|
||||
self.assertResponse('setconf confDir', 'confDir is a string.')
|
||||
self.assertResponse('setconf whackyConfOption',
|
||||
'Error: That conf variable doesn\'t exist.')
|
||||
try:
|
||||
originalConfAllowEval = conf.allowEval
|
||||
conf.allowEval = False
|
||||
|
|
Loading…
Reference in New Issue