Refactoring of error-related configuration variables.

This commit is contained in:
Jeremy Fincher 2004-11-04 05:34:24 +00:00
parent b8216a6bd5
commit 040888405c
4 changed files with 21 additions and 22 deletions

View File

@ -176,8 +176,8 @@ def reply(msg, s, prefixName=None, private=None,
if prefixName is None:
prefixName = conf.get(conf.supybot.reply.withNickPrefix, channel)
if error:
notice =conf.get(conf.supybot.reply.errorWithNotice, channel) or notice
private=conf.get(conf.supybot.reply.errorInPrivate, channel) or private
notice =conf.get(conf.supybot.reply.error.withNotice, channel) or notice
private=conf.get(conf.supybot.reply.error.inPrivate, channel) or private
s = 'Error: ' + s
if private:
prefixName = False
@ -486,10 +486,11 @@ class RichReplyMethods(object):
if isinstance(capability, basestring): # checkCommandCapability!
log.warning('Denying %s for lacking %s 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)
s = self.__makeReply(v % capability, s)
return self._error(s, **kwargs)
# XXX We should log that we're *not* giving a capability error.
else:
log.warning('Denying %s for some unspecified capability '
'(or a default).', self.msg.prefix)
@ -649,7 +650,7 @@ class IrcObjectProxy(RichReplyMethods):
except Exception, e:
cb.log.exception('Uncaught exception in %s.%s:',
cb.name(), name)
if conf.supybot.reply.detailedErrors():
if conf.supybot.reply.error.detailed():
return self.error(utils.exnToString(e))
else:
return self.replyError()

View File

@ -308,26 +308,24 @@ registerChannelValue(supybot.reply, 'whenNotCommand',
error message when it is addressed but not given a valid command. If this
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
from bugs in the bot will show a detailed error message (the uncaught
exception) or a generic error message."""))
registerChannelValue(supybot.reply, 'errorInPrivate',
registerChannelValue(supybot.reply.error, 'inPrivate',
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
channel traffic to minimum. This can be used in combination with
supybot.reply.errorWithNotice."""))
registerChannelValue(supybot.reply, 'errorWithNotice',
registerChannelValue(supybot.reply.error, 'withNotice',
registry.Boolean(False, """Determines whether the bot will send error
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
messages; or you might want to use it in combination with
supybot.reply.errorInPrivate so private errors don't open a query window
in most IRC clients."""))
registerChannelValue(supybot.reply, 'noCapabilityError',
registerChannelValue(supybot.reply.error, 'noCapability',
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
the necessary capability. You may wish to make this True if you don't want

View File

@ -307,31 +307,31 @@ class PrivmsgTestCase(ChannelPluginTestCase):
def testErrorPrivateKwarg(self):
try:
original = conf.supybot.reply.errorInPrivate()
conf.supybot.reply.errorInPrivate.setValue(False)
original = conf.supybot.reply.error.inPrivate()
conf.supybot.reply.error.inPrivate.setValue(False)
m = self.getMsg("eval irc.error('foo', private=True)")
self.failUnless(m, 'No message returned.')
self.failIf(ircutils.isChannel(m.args[0]))
finally:
conf.supybot.reply.errorInPrivate.setValue(original)
conf.supybot.reply.error.inPrivate.setValue(original)
def testErrorNoArgumentIsArgumentError(self):
self.assertHelp('eval irc.error()')
def testErrorWithNotice(self):
try:
original = conf.supybot.reply.errorWithNotice()
conf.supybot.reply.errorWithNotice.setValue(True)
original = conf.supybot.reply.error.withNotice()
conf.supybot.reply.error.withNotice.setValue(True)
m = self.getMsg("eval irc.error('foo')")
self.failUnless(m, 'No message returned.')
self.failUnless(m.command == 'NOTICE')
finally:
conf.supybot.reply.errorWithNotice.setValue(original)
conf.supybot.reply.error.withNotice.setValue(original)
def testErrorReplyPrivate(self):
try:
original = str(conf.supybot.reply.errorInPrivate)
conf.supybot.reply.errorInPrivate.set('False')
original = str(conf.supybot.reply.error.inPrivate)
conf.supybot.reply.error.inPrivate.set('False')
# 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
# expect to error actually does so we don't go on a wild goose
@ -340,11 +340,11 @@ class PrivmsgTestCase(ChannelPluginTestCase):
self.assertError(s)
m = self.getMsg(s)
self.failUnless(ircutils.isChannel(m.args[0]))
conf.supybot.reply.errorInPrivate.set('True')
conf.supybot.reply.error.inPrivate.set('True')
m = self.getMsg(s)
self.failIf(ircutils.isChannel(m.args[0]))
finally:
conf.supybot.reply.errorInPrivate.set(original)
conf.supybot.reply.error.inPrivate.set(original)
# Now for stuff not based on the plugins.
class First(callbacks.Privmsg):

View File

@ -146,7 +146,7 @@ class PluginTestCase(SupyTestCase):
irc._reallyDie()
# Set conf variables appropriately.
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)
self.myVerbose = world.myVerbose
def rmFiles(dir):