mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Refactoring of error-related configuration variables.
This commit is contained in:
parent
b8216a6bd5
commit
040888405c
@ -176,8 +176,8 @@ def reply(msg, s, prefixName=None, private=None,
|
|||||||
if prefixName is None:
|
if prefixName is None:
|
||||||
prefixName = conf.get(conf.supybot.reply.withNickPrefix, channel)
|
prefixName = conf.get(conf.supybot.reply.withNickPrefix, channel)
|
||||||
if error:
|
if error:
|
||||||
notice =conf.get(conf.supybot.reply.errorWithNotice, channel) or notice
|
notice =conf.get(conf.supybot.reply.error.withNotice, channel) or notice
|
||||||
private=conf.get(conf.supybot.reply.errorInPrivate, channel) or private
|
private=conf.get(conf.supybot.reply.error.inPrivate, channel) or private
|
||||||
s = 'Error: ' + s
|
s = 'Error: ' + s
|
||||||
if private:
|
if private:
|
||||||
prefixName = False
|
prefixName = False
|
||||||
@ -486,10 +486,11 @@ class RichReplyMethods(object):
|
|||||||
if isinstance(capability, basestring): # checkCommandCapability!
|
if isinstance(capability, basestring): # checkCommandCapability!
|
||||||
log.warning('Denying %s for lacking %s capability.',
|
log.warning('Denying %s for lacking %s capability.',
|
||||||
self.msg.prefix, utils.quoted(capability))
|
self.msg.prefix, utils.quoted(capability))
|
||||||
if not self._getConfig(conf.supybot.reply.noCapabilityError):
|
if not self._getConfig(conf.supybot.reply.error.noCapability):
|
||||||
v = self._getConfig(conf.supybot.replies.noCapability)
|
v = self._getConfig(conf.supybot.replies.noCapability)
|
||||||
s = self.__makeReply(v % capability, s)
|
s = self.__makeReply(v % capability, s)
|
||||||
return self._error(s, **kwargs)
|
return self._error(s, **kwargs)
|
||||||
|
# XXX We should log that we're *not* giving a capability error.
|
||||||
else:
|
else:
|
||||||
log.warning('Denying %s for some unspecified capability '
|
log.warning('Denying %s for some unspecified capability '
|
||||||
'(or a default).', self.msg.prefix)
|
'(or a default).', self.msg.prefix)
|
||||||
@ -649,7 +650,7 @@ class IrcObjectProxy(RichReplyMethods):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
cb.log.exception('Uncaught exception in %s.%s:',
|
cb.log.exception('Uncaught exception in %s.%s:',
|
||||||
cb.name(), name)
|
cb.name(), name)
|
||||||
if conf.supybot.reply.detailedErrors():
|
if conf.supybot.reply.error.detailed():
|
||||||
return self.error(utils.exnToString(e))
|
return self.error(utils.exnToString(e))
|
||||||
else:
|
else:
|
||||||
return self.replyError()
|
return self.replyError()
|
||||||
|
12
src/conf.py
12
src/conf.py
@ -308,26 +308,24 @@ registerChannelValue(supybot.reply, 'whenNotCommand',
|
|||||||
error message when it is addressed but not given a valid command. If this
|
error message when it is addressed but not given a valid command. If this
|
||||||
value is False, the bot will remain silent."""))
|
value is False, the bot will remain silent."""))
|
||||||
|
|
||||||
registerGlobalValue(supybot.reply, 'detailedErrors',
|
registerGroup(supybot.reply, 'error')
|
||||||
|
registerGlobalValue(supybot.reply.error, 'detailed',
|
||||||
registry.Boolean(False, """Determines whether error messages that result
|
registry.Boolean(False, """Determines whether error messages that result
|
||||||
from bugs in the bot will show a detailed error message (the uncaught
|
from bugs in the bot will show a detailed error message (the uncaught
|
||||||
exception) or a generic error message."""))
|
exception) or a generic error message."""))
|
||||||
|
registerChannelValue(supybot.reply.error, 'inPrivate',
|
||||||
registerChannelValue(supybot.reply, 'errorInPrivate',
|
|
||||||
registry.Boolean(False, """Determines whether the bot will send error
|
registry.Boolean(False, """Determines whether the bot will send error
|
||||||
messages to users in private. You might want to do this in order to keep
|
messages to users in private. You might want to do this in order to keep
|
||||||
channel traffic to minimum. This can be used in combination with
|
channel traffic to minimum. This can be used in combination with
|
||||||
supybot.reply.errorWithNotice."""))
|
supybot.reply.errorWithNotice."""))
|
||||||
|
registerChannelValue(supybot.reply.error, 'withNotice',
|
||||||
registerChannelValue(supybot.reply, 'errorWithNotice',
|
|
||||||
registry.Boolean(False, """Determines whether the bot will send error
|
registry.Boolean(False, """Determines whether the bot will send error
|
||||||
messages to users via NOTICE instead of PRIVMSG. You might want to do this
|
messages to users via NOTICE instead of PRIVMSG. You might want to do this
|
||||||
so users can ignore NOTICEs from the bot and not have to see error
|
so users can ignore NOTICEs from the bot and not have to see error
|
||||||
messages; or you might want to use it in combination with
|
messages; or you might want to use it in combination with
|
||||||
supybot.reply.errorInPrivate so private errors don't open a query window
|
supybot.reply.errorInPrivate so private errors don't open a query window
|
||||||
in most IRC clients."""))
|
in most IRC clients."""))
|
||||||
|
registerChannelValue(supybot.reply.error, 'noCapability',
|
||||||
registerChannelValue(supybot.reply, 'noCapabilityError',
|
|
||||||
registry.Boolean(False, """Determines whether the bot will send an error
|
registry.Boolean(False, """Determines whether the bot will send an error
|
||||||
message to users who attempt to call a command for which they do not have
|
message to users who attempt to call a command for which they do not have
|
||||||
the necessary capability. You may wish to make this True if you don't want
|
the necessary capability. You may wish to make this True if you don't want
|
||||||
|
@ -307,31 +307,31 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
def testErrorPrivateKwarg(self):
|
def testErrorPrivateKwarg(self):
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.reply.errorInPrivate()
|
original = conf.supybot.reply.error.inPrivate()
|
||||||
conf.supybot.reply.errorInPrivate.setValue(False)
|
conf.supybot.reply.error.inPrivate.setValue(False)
|
||||||
m = self.getMsg("eval irc.error('foo', private=True)")
|
m = self.getMsg("eval irc.error('foo', private=True)")
|
||||||
self.failUnless(m, 'No message returned.')
|
self.failUnless(m, 'No message returned.')
|
||||||
self.failIf(ircutils.isChannel(m.args[0]))
|
self.failIf(ircutils.isChannel(m.args[0]))
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.reply.errorInPrivate.setValue(original)
|
conf.supybot.reply.error.inPrivate.setValue(original)
|
||||||
|
|
||||||
def testErrorNoArgumentIsArgumentError(self):
|
def testErrorNoArgumentIsArgumentError(self):
|
||||||
self.assertHelp('eval irc.error()')
|
self.assertHelp('eval irc.error()')
|
||||||
|
|
||||||
def testErrorWithNotice(self):
|
def testErrorWithNotice(self):
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.reply.errorWithNotice()
|
original = conf.supybot.reply.error.withNotice()
|
||||||
conf.supybot.reply.errorWithNotice.setValue(True)
|
conf.supybot.reply.error.withNotice.setValue(True)
|
||||||
m = self.getMsg("eval irc.error('foo')")
|
m = self.getMsg("eval irc.error('foo')")
|
||||||
self.failUnless(m, 'No message returned.')
|
self.failUnless(m, 'No message returned.')
|
||||||
self.failUnless(m.command == 'NOTICE')
|
self.failUnless(m.command == 'NOTICE')
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.reply.errorWithNotice.setValue(original)
|
conf.supybot.reply.error.withNotice.setValue(original)
|
||||||
|
|
||||||
def testErrorReplyPrivate(self):
|
def testErrorReplyPrivate(self):
|
||||||
try:
|
try:
|
||||||
original = str(conf.supybot.reply.errorInPrivate)
|
original = str(conf.supybot.reply.error.inPrivate)
|
||||||
conf.supybot.reply.errorInPrivate.set('False')
|
conf.supybot.reply.error.inPrivate.set('False')
|
||||||
# If this doesn't raise an error, we've got a problem, so the next
|
# If this doesn't raise an error, we've got a problem, so the next
|
||||||
# two assertions shouldn't run. So we first check that what we
|
# two assertions shouldn't run. So we first check that what we
|
||||||
# expect to error actually does so we don't go on a wild goose
|
# expect to error actually does so we don't go on a wild goose
|
||||||
@ -340,11 +340,11 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
|||||||
self.assertError(s)
|
self.assertError(s)
|
||||||
m = self.getMsg(s)
|
m = self.getMsg(s)
|
||||||
self.failUnless(ircutils.isChannel(m.args[0]))
|
self.failUnless(ircutils.isChannel(m.args[0]))
|
||||||
conf.supybot.reply.errorInPrivate.set('True')
|
conf.supybot.reply.error.inPrivate.set('True')
|
||||||
m = self.getMsg(s)
|
m = self.getMsg(s)
|
||||||
self.failIf(ircutils.isChannel(m.args[0]))
|
self.failIf(ircutils.isChannel(m.args[0]))
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.reply.errorInPrivate.set(original)
|
conf.supybot.reply.error.inPrivate.set(original)
|
||||||
|
|
||||||
# Now for stuff not based on the plugins.
|
# Now for stuff not based on the plugins.
|
||||||
class First(callbacks.Privmsg):
|
class First(callbacks.Privmsg):
|
||||||
|
@ -146,7 +146,7 @@ class PluginTestCase(SupyTestCase):
|
|||||||
irc._reallyDie()
|
irc._reallyDie()
|
||||||
# Set conf variables appropriately.
|
# Set conf variables appropriately.
|
||||||
conf.supybot.reply.whenAddressedBy.chars.setValue('@')
|
conf.supybot.reply.whenAddressedBy.chars.setValue('@')
|
||||||
conf.supybot.reply.detailedErrors.setValue(True)
|
conf.supybot.reply.error.detailed.setValue(True)
|
||||||
conf.supybot.reply.whenNotCommand.setValue(True)
|
conf.supybot.reply.whenNotCommand.setValue(True)
|
||||||
self.myVerbose = world.myVerbose
|
self.myVerbose = world.myVerbose
|
||||||
def rmFiles(dir):
|
def rmFiles(dir):
|
||||||
|
Loading…
Reference in New Issue
Block a user