We should return the message from errors/replies.

This commit is contained in:
Jeremy Fincher 2004-09-28 07:16:32 +00:00
parent 4b5909331a
commit 9ca87988ae

View File

@ -416,12 +416,12 @@ class RichReplyMethods(object):
def replySuccess(self, s='', **kwargs): def replySuccess(self, s='', **kwargs):
v = self._getConfig(conf.supybot.replies.success) v = self._getConfig(conf.supybot.replies.success)
s = self.__makeReply(v, s) s = self.__makeReply(v, s)
self.reply(s, **kwargs) return self.reply(s, **kwargs)
def replyError(self, s='', **kwargs): def replyError(self, s='', **kwargs):
v = self._getConfig(conf.supybot.replies.error) v = self._getConfig(conf.supybot.replies.error)
s = self.__makeReply(v, s) s = self.__makeReply(v, s)
self.reply(s, **kwargs) return self.reply(s, **kwargs)
def replies(self, L, prefixer=None, joiner=None, def replies(self, L, prefixer=None, joiner=None,
onlyPrefixFirst=False, **kwargs): onlyPrefixFirst=False, **kwargs):
@ -434,18 +434,18 @@ class RichReplyMethods(object):
if isinstance(joiner, basestring): if isinstance(joiner, basestring):
joiner = joiner.join joiner = joiner.join
if conf.supybot.reply.oneToOne(): if conf.supybot.reply.oneToOne():
self.reply(prefixer(joiner(L)), **kwargs) return self.reply(prefixer(joiner(L)), **kwargs)
else: else:
first = True first = True
for s in L: for s in L:
if onlyPrefixFirst: if onlyPrefixFirst:
if first: if first:
self.reply(prefixer(s), **kwargs)
first = False first = False
return self.reply(prefixer(s), **kwargs)
else: else:
self.reply(s, **kwargs) return self.reply(s, **kwargs)
else: else:
self.reply(prefixer(s), **kwargs) return self.reply(prefixer(s), **kwargs)
def noReply(self): def noReply(self):
self.msg.tag('repliedTo') self.msg.tag('repliedTo')
@ -454,7 +454,7 @@ class RichReplyMethods(object):
if Raise: if Raise:
raise Error, s raise Error, s
else: else:
self.error(s, **kwargs) return self.error(s, **kwargs)
def errorNoCapability(self, capability, s='', **kwargs): def errorNoCapability(self, capability, s='', **kwargs):
if isinstance(capability, basestring): # checkCommandCapability! if isinstance(capability, basestring): # checkCommandCapability!
@ -463,12 +463,12 @@ class RichReplyMethods(object):
if not self._getConfig(conf.supybot.reply.noCapabilityError): if not self._getConfig(conf.supybot.reply.noCapabilityError):
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)
self._error(s, **kwargs) return self._error(s, **kwargs)
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)
v = self._getConfig(conf.supybot.replies.genericNoCapability) v = self._getConfig(conf.supybot.replies.genericNoCapability)
self._error(self.__makeReply(v, s), **kwargs) return self._error(self.__makeReply(v, s), **kwargs)
def errorPossibleBug(self, s='', **kwargs): def errorPossibleBug(self, s='', **kwargs):
v = self._getConfig(conf.supybot.replies.possibleBug) v = self._getConfig(conf.supybot.replies.possibleBug)
@ -476,11 +476,11 @@ class RichReplyMethods(object):
s += ' (%s)' % v s += ' (%s)' % v
else: else:
s = v s = v
self._error(s, **kwargs) return self._error(s, **kwargs)
def errorNotRegistered(self, s='', **kwargs): def errorNotRegistered(self, s='', **kwargs):
v = self._getConfig(conf.supybot.replies.notRegistered) v = self._getConfig(conf.supybot.replies.notRegistered)
self._error(self.__makeReply(v, s), **kwargs) return self._error(self.__makeReply(v, s), **kwargs)
def errorNoUser(self, s='', name='that user', **kwargs): def errorNoUser(self, s='', name='that user', **kwargs):
v = self._getConfig(conf.supybot.replies.noUser) v = self._getConfig(conf.supybot.replies.noUser)
@ -488,11 +488,11 @@ class RichReplyMethods(object):
v = v % name v = v % name
except TypeError: except TypeError:
log.warning('supybot.replies.noUser should have one "%s" in it.') log.warning('supybot.replies.noUser should have one "%s" in it.')
self._error(self.__makeReply(v, s), **kwargs) return self._error(self.__makeReply(v, s), **kwargs)
def errorRequiresPrivacy(self, s='', **kwargs): def errorRequiresPrivacy(self, s='', **kwargs):
v = self._getConfig(conf.supybot.replies.requiresPrivacy) v = self._getConfig(conf.supybot.replies.requiresPrivacy)
self._error(self.__makeReply(v, s), **kwargs) return self._error(self.__makeReply(v, s), **kwargs)
def errorInvalid(self, what, given=None, s='', repr=True, **kwargs): def errorInvalid(self, what, given=None, s='', repr=True, **kwargs):
if given is not None: if given is not None:
@ -503,7 +503,7 @@ class RichReplyMethods(object):
v = '%s is not a valid %s.' % (given, what) v = '%s is not a valid %s.' % (given, what)
else: else:
v = 'That\'s not a valid %s.' % what v = 'That\'s not a valid %s.' % what
self._error(self.__makeReply(v, s), **kwargs) return self._error(self.__makeReply(v, s), Raise=True, **kwargs)
_repr = repr _repr = repr
@ -521,9 +521,8 @@ class IrcObjectProxy(RichReplyMethods):
if maxNesting and self.nested > maxNesting: if maxNesting and self.nested > maxNesting:
log.warning('%s attempted more than %s levels of nesting.', log.warning('%s attempted more than %s levels of nesting.',
self.msg.prefix, maxNesting) self.msg.prefix, maxNesting)
self.error('You\'ve attempted more nesting than is currently ' return self.error('You\'ve attempted more nesting than is '
'allowed on this bot.') 'currently allowed on this bot.')
return
# The deepcopy here is necessary for Scheduler; it re-runs already # The deepcopy here is necessary for Scheduler; it re-runs already
# tokenized commands. # tokenized commands.
self.args = copy.deepcopy(args) self.args = copy.deepcopy(args)
@ -580,7 +579,7 @@ class IrcObjectProxy(RichReplyMethods):
try: try:
cb.tokenizedCommand(self, self.msg, self.args) cb.tokenizedCommand(self, self.msg, self.args)
except Error, e: except Error, e:
self.error(str(e)) return self.error(str(e))
except Exception, e: except Exception, e:
log.exception('Uncaught exception in %s.tokenizedCommand.' % log.exception('Uncaught exception in %s.tokenizedCommand.' %
cb.name()) cb.name())
@ -599,7 +598,7 @@ class IrcObjectProxy(RichReplyMethods):
try: try:
cb.invalidCommand(self, self.msg, self.args) cb.invalidCommand(self, self.msg, self.args)
except Error, e: except Error, e:
self.error(str(e)) return self.error(str(e))
except Exception, e: except Exception, e:
log.exception('Uncaught exception in %s.invalidCommand.'% log.exception('Uncaught exception in %s.invalidCommand.'%
cb.name()) cb.name())
@ -613,9 +612,9 @@ class IrcObjectProxy(RichReplyMethods):
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.detailedErrors():
self.error(utils.exnToString(e)) return self.error(utils.exnToString(e))
else: else:
self.replyError() return self.replyError()
finally: finally:
self.commandMethod = None self.commandMethod = None
@ -693,10 +692,13 @@ class IrcObjectProxy(RichReplyMethods):
# No matching regexp commands, now we do invalidCommands. # No matching regexp commands, now we do invalidCommands.
self._callInvalidCommands() self._callInvalidCommands()
elif len(cbs) > 1: elif len(cbs) > 1:
self.error('The command %s is available in the %s plugins. ' return self.error('The command %s is available in the %s plugins. '
'Please specify the plugin whose command you wish ' 'Please specify the plugin whose command you '
'to call by using its name as a command before %s.' % 'wish to call by using its name as a command '
(command, sorted([cb.name() for cb in cbs]), command)) 'before %s.' %
(command,
sorted([cb.name() for cb in cbs]),
command))
else: else:
cb = cbs[0] cb = cbs[0]
del self.args[0] # Remove the command. del self.args[0] # Remove the command.
@ -749,20 +751,22 @@ class IrcObjectProxy(RichReplyMethods):
s = s[:conf.supybot.reply.maximumLength()] s = s[:conf.supybot.reply.maximumLength()]
if conf.get(conf.supybot.reply.truncate, self.msg.args[0]): if conf.get(conf.supybot.reply.truncate, self.msg.args[0]):
s = s[:512] s = s[:512]
self.irc.reply(s, to=self.to, return self.irc.reply(s, to=self.to,
notice=self.notice, notice=self.notice,
action=self.action, action=self.action,
private=self.private, private=self.private,
prefixName=self.prefixName, prefixName=self.prefixName,
noLengthCheck=self.noLengthCheck) noLengthCheck=self.noLengthCheck)
elif self.noLengthCheck: elif self.noLengthCheck:
# noLengthCheck only matters to IrcObjectProxy, so it's not # noLengthCheck only matters to IrcObjectProxy, so it's not
# used here. Just in case you were wondering. # used here. Just in case you were wondering.
self.irc.queueMsg(reply(msg, s, to=self.to, m = reply(msg, s, to=self.to,
notice=self.notice, notice=self.notice,
action=self.action, action=self.action,
private=self.private, private=self.private,
prefixName=self.prefixName)) prefixName=self.prefixName)
self.irc.queueMsg(m)
return m
else: else:
s = ircutils.safeArgument(s) s = ircutils.safeArgument(s)
allowedLength = 450 - len(self.irc.prefix) allowedLength = 450 - len(self.irc.prefix)
@ -834,13 +838,16 @@ class IrcObjectProxy(RichReplyMethods):
raise ArgumentError raise ArgumentError
if s: if s:
if not isinstance(self.irc, irclib.Irc): if not isinstance(self.irc, irclib.Irc):
self.irc.error(s, **kwargs) return self.irc.error(s, **kwargs)
else: else:
self.irc.queueMsg(error(self.msg, s, **kwargs)) m = error(self.msg, s, **kwargs)
self.irc.queueMsg(m)
return m
else: else:
if self.commandMethod is not None: if self.commandMethod is not None:
# We can recurse here because it only gets called once. # We can recurse here because it only gets called once.
self.error(formatArgumentError(self.commandMethod), **kwargs) return self.error(formatArgumentError(self.commandMethod),
**kwargs)
else: else:
raise ArgumentError # We shouldn't get here, but just in case. raise ArgumentError # We shouldn't get here, but just in case.