mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
RFE #807340: OwnerCommands command for setting conf variables.
This commit is contained in:
parent
f137b21dcf
commit
cae8905594
@ -102,6 +102,37 @@ class OwnerCommands(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error(msg, conf.replyEvalNotAllowed)
|
irc.error(msg, conf.replyEvalNotAllowed)
|
||||||
|
|
||||||
|
def setconf(self, irc, msg, args):
|
||||||
|
"""<name> <value>
|
||||||
|
|
||||||
|
Sets the value of the conf-module variable <name> to <value>.
|
||||||
|
"""
|
||||||
|
(name, value) = privmsgs.getArgs(args, needed=2)
|
||||||
|
if conf.allowEval:
|
||||||
|
try:
|
||||||
|
value = eval(value)
|
||||||
|
except Exception, e:
|
||||||
|
irc.error(msg, debug.exnToString(e))
|
||||||
|
return
|
||||||
|
setattr(conf, name, value)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
else:
|
||||||
|
if name == 'allowEval':
|
||||||
|
irc.error(msg, 'You can\'t set the value of allowEval.')
|
||||||
|
return
|
||||||
|
elif name not in conf.types:
|
||||||
|
irc.error(msg, 'I can\'t set that conf variable.')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
converter = conf.types[name]
|
||||||
|
try:
|
||||||
|
value = converter(value)
|
||||||
|
except ValueError, e:
|
||||||
|
irc.error(msg, str(e))
|
||||||
|
return
|
||||||
|
setattr(conf, name, value)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
def setdefaultcapability(self, irc, msg, args):
|
def setdefaultcapability(self, irc, msg, args):
|
||||||
"""<capability>
|
"""<capability>
|
||||||
|
|
||||||
|
59
src/conf.py
59
src/conf.py
@ -178,11 +178,6 @@ nickmods = ['%s^', '^%s^', '__%s__', '%s_', '%s__', '__%s', '^^%s^^', '{%s}',
|
|||||||
###
|
###
|
||||||
defaultAllow = True
|
defaultAllow = True
|
||||||
|
|
||||||
###
|
|
||||||
# defaultChannelAllow: does an IrcChannel allow a command by by default?
|
|
||||||
###
|
|
||||||
defaultChannelAllow = True
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# defaultIgnore: True if users should be ignored by default.
|
# defaultIgnore: True if users should be ignored by default.
|
||||||
# It's a really easy way to make sure that people who want to
|
# It's a really easy way to make sure that people who want to
|
||||||
@ -227,4 +222,58 @@ version ='0.72.0'
|
|||||||
|
|
||||||
commandsOnStart = []
|
commandsOnStart = []
|
||||||
|
|
||||||
|
# This is a dictionary mapping names to converter functions for use in the
|
||||||
|
# OwnerCommands.setconf command.
|
||||||
|
def mybool(s):
|
||||||
|
if s.capitalize() == 'False' or s == '0':
|
||||||
|
return False
|
||||||
|
elif s.capitalize() == 'True' or s == '1':
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise ValueError, 'invalid literal for mybool()'
|
||||||
|
|
||||||
|
def mystr(s):
|
||||||
|
while s and s[0] in "'\"" and s[0] == s[-1]:
|
||||||
|
s = s[1:-1]
|
||||||
|
return s
|
||||||
|
|
||||||
|
types = {
|
||||||
|
'logDir': mystr,
|
||||||
|
'confDir': mystr,
|
||||||
|
'dataDir': mystr,
|
||||||
|
#'pluginDirs': (list, str),
|
||||||
|
'userfile': mystr,
|
||||||
|
'channelfile': mystr,
|
||||||
|
'logTimestampFormat': mystr,
|
||||||
|
'humanTimestampFormat': mystr,
|
||||||
|
'throttleTime': float,
|
||||||
|
#'allowEval': mybool,
|
||||||
|
'replyWhenNotCommand': mybool,
|
||||||
|
'requireRegistration': mybool,
|
||||||
|
'enablePipeSyntax': mybool,
|
||||||
|
'replyError': mystr,
|
||||||
|
'replyNoCapability': mystr,
|
||||||
|
'replySuccess': mystr,
|
||||||
|
'replyIncorrectAuth': mystr,
|
||||||
|
'replyNoUser': mystr,
|
||||||
|
'replyNotRegistered': mystr,
|
||||||
|
'replyInvalidArgument': mystr,
|
||||||
|
'replyRequiresPrivacy': mystr,
|
||||||
|
'replyEvalNotAllowed': mystr,
|
||||||
|
'errorReplyPrivate': mybool,
|
||||||
|
#'telnetEnable': mybool,
|
||||||
|
#'telnetPort': int,
|
||||||
|
'poll': float,
|
||||||
|
#'maxHistory': int,
|
||||||
|
'pingInterval': float,
|
||||||
|
#'nickmods': (list, str),
|
||||||
|
'defaultAllow': mybool,
|
||||||
|
'defaultIgnore': mybool,
|
||||||
|
#'ignores': (list, str),
|
||||||
|
'prefixChars': mystr,
|
||||||
|
'detailedTracebacks': mybool,
|
||||||
|
'driverModule': mystr,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -36,15 +36,28 @@ import conf
|
|||||||
class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||||
plugins = ('OwnerCommands',)
|
plugins = ('OwnerCommands',)
|
||||||
def testEval(self):
|
def testEval(self):
|
||||||
conf.allowEval = True
|
try:
|
||||||
s = "[irc.__class__ for irc in " \
|
originalConfAllowEval = conf.allowEval
|
||||||
"irc.getCallback('Relay').ircstates.keys()]"
|
conf.allowEval = True
|
||||||
self.assertNotRegexp('eval ' + s, '^SyntaxError')
|
s = "[irc.__class__ for irc in " \
|
||||||
|
"irc.getCallback('Relay').ircstates.keys()]"
|
||||||
|
self.assertNotRegexp('eval ' + s, '^SyntaxError')
|
||||||
|
conf.allowEval = False
|
||||||
|
self.assertError('eval 100')
|
||||||
|
finally:
|
||||||
|
conf.allowEval = originalConfAllowEval
|
||||||
|
|
||||||
def testExec(self):
|
def testExec(self):
|
||||||
self.assertNotError('exec conf.foo = True')
|
try:
|
||||||
self.failUnless(conf.foo)
|
originalConfAllowEval = conf.allowEval
|
||||||
del conf.foo
|
conf.allowEval = True
|
||||||
|
self.assertNotError('exec conf.foo = True')
|
||||||
|
self.failUnless(conf.foo)
|
||||||
|
del conf.foo
|
||||||
|
conf.allowEval = False
|
||||||
|
self.assertError('exec conf.foo = True')
|
||||||
|
finally:
|
||||||
|
conf.allowEval = originalConfAllowEval
|
||||||
|
|
||||||
def testSettrace(self):
|
def testSettrace(self):
|
||||||
self.assertNotError('settrace')
|
self.assertNotError('settrace')
|
||||||
@ -84,6 +97,38 @@ class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
|
|
||||||
def testSay(self):
|
def testSay(self):
|
||||||
self.assertResponse('say %s foo' % self.irc.nick, 'foo')
|
self.assertResponse('say %s foo' % self.irc.nick, 'foo')
|
||||||
|
|
||||||
|
def testSetconf(self):
|
||||||
|
try:
|
||||||
|
originalConfAllowEval = conf.allowEval
|
||||||
|
conf.allowEval = False
|
||||||
|
self.assertError('setconf alsdkfj 100')
|
||||||
|
self.assertError('setconf poll "foo"')
|
||||||
|
try:
|
||||||
|
originalReplySuccess = conf.replySuccess
|
||||||
|
self.assertResponse('setconf replySuccess foo', 'foo')
|
||||||
|
self.assertResponse('setconf replySuccess "foo"', 'foo')
|
||||||
|
self.assertResponse('setconf replySuccess \'foo\'', 'foo')
|
||||||
|
finally:
|
||||||
|
conf.replySuccess = originalReplySuccess
|
||||||
|
try:
|
||||||
|
originalReplyWhenNotCommand = conf.replyWhenNotCommand
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand True')
|
||||||
|
self.failUnless(conf.replyWhenNotCommand)
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand False')
|
||||||
|
self.failIf(conf.replyWhenNotCommand)
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand true')
|
||||||
|
self.failUnless(conf.replyWhenNotCommand)
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand false')
|
||||||
|
self.failIf(conf.replyWhenNotCommand)
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand 1')
|
||||||
|
self.failUnless(conf.replyWhenNotCommand)
|
||||||
|
self.assertNotError('setconf replyWhenNotCommand 0')
|
||||||
|
self.failIf(conf.replyWhenNotCommand)
|
||||||
|
finally:
|
||||||
|
conf.replyWhenNotCommand = originalReplyWhenNotCommand
|
||||||
|
finally:
|
||||||
|
conf.allowEval = originalConfAllowEval
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user