diff --git a/src/Misc.py b/src/Misc.py index e864e4d4f..b36851ac0 100755 --- a/src/Misc.py +++ b/src/Misc.py @@ -71,6 +71,16 @@ conf.registerGlobalValue(conf.supybot.plugins.Misc, 'timestampFormat', timestamps in the Misc.last command. Refer to the Python documentation for the time module to see what formats are accepted. If you set this variable to the empty string, the timestamp will not be shown.""")) +conf.registerGroup(conf.supybot.plugins.Misc, 'last') +conf.registerGroup(conf.supybot.plugins.Misc.last, 'nested') +conf.registerChannelValue(conf.supybot.plugins.Misc.last.nested, + 'includeTimestamp', registry.Boolean(False, """Determines whether or not + the timestamp will be included in the output of last when it is part of a + nested command""")) +conf.registerChannelValue(conf.supybot.plugins.Misc.last.nested, + 'includeNick', registry.Boolean(False, """Determines whether or not the + nick will be included in the output of last when it is part of a nested + command""")) class Misc(callbacks.Privmsg): def __init__(self): @@ -488,16 +498,28 @@ class Misc(callbacks.Privmsg): iterable.next() # Drop the first message. predicates = list(utils.flatten(predicates.itervalues())) resp = [] - tsf = self.registryValue('timestampFormat') + if irc.nested and not \ + self.registryValue('last.nested.includeTimestamp'): + tsf = None + else: + tsf = self.registryValue('timestampFormat') + if irc.nested and not self.registryValue('last.nested.includeNick'): + showNick = False + else: + showNick = True for m in iterable: for predicate in predicates: if not predicate(m): break else: if nolimit: - resp.append(ircmsgs.prettyPrint(m, timestampFormat=tsf)) + resp.append(ircmsgs.prettyPrint(m, + timestampFormat=tsf, + showNick=showNick)) else: - irc.reply(ircmsgs.prettyPrint(m, timestampFormat=tsf)) + irc.reply(ircmsgs.prettyPrint(m, + timestampFormat=tsf, + showNick=showNick)) return if not resp: irc.error('I couldn\'t find a message matching that criteria in ' diff --git a/src/ircmsgs.py b/src/ircmsgs.py index fc1c51a79..64670f1ae 100644 --- a/src/ircmsgs.py +++ b/src/ircmsgs.py @@ -267,7 +267,7 @@ def toXml(msg, pretty=True, includeTime=True): L.append('\n') return ''.join(L) -def prettyPrint(msg, addRecipients=False, timestampFormat=None): +def prettyPrint(msg, addRecipients=False, timestampFormat=None, showNick=True): """Provides a client-friendly string form for messages. IIRC, I copied BitchX's (or was it XChat's?) format for messages. @@ -284,9 +284,15 @@ def prettyPrint(msg, addRecipients=False, timestampFormat=None): if m: s = '* %s %s' % (nick(), m.group(1)) else: - s = '<%s> %s' % (nick(), msg.args[1]) + if not showNick: + s = '%s' % msg.args[1] + else: + s = '<%s> %s' % (nick(), msg.args[1]) elif msg.command == 'NOTICE': - s = '-%s- %s' % (nick(), msg.args[1]) + if not showNick: + s = '%s' % msg.args[1] + else: + s = '-%s- %s' % (nick(), msg.args[1]) elif msg.command == 'JOIN': s = '*** %s has joined %s' % (msg.nick, msg.args[0]) elif msg.command == 'PART': @@ -311,7 +317,7 @@ def prettyPrint(msg, addRecipients=False, timestampFormat=None): s = '*** %s has quit IRC%s' % (msg.nick, quitmsg) elif msg.command == 'TOPIC': s = '*** %s changes topic to %s' % (nickorprefix(), msg.args[1]) - at = getattr(msg, 'receivedAt', False) + at = getattr(msg, 'receivedAt', None) if timestampFormat and at: s = '%s %s' % (time.strftime(timestampFormat, time.localtime(at)), s) return s diff --git a/test/test_Misc.py b/test/test_Misc.py index 71550a6ac..18e1cd978 100644 --- a/test/test_Misc.py +++ b/test/test_Misc.py @@ -188,6 +188,28 @@ class MiscTestCase(ChannelPluginTestCase): finally: conf.supybot.plugins.Misc.timestampFormat.setValue(orig) + def testNestedLastTimestampConfig(self): + tsConfig = conf.supybot.plugins.Misc.last.nested.includeTimestamp + orig = tsConfig() + try: + tsConfig.setValue(True) + self.feedMsg('foo bar baz') + self.assertRegexp('echo [last]', + '\[\d+:\d+:\d+\] foo bar baz') + finally: + tsConfig.setValue(orig) + + def testNestedLastNickConfig(self): + nickConfig = conf.supybot.plugins.Misc.last.nested.includeNick + orig = nickConfig() + try: + nickConfig.setValue(True) + self.feedMsg('foo bar baz') + self.assertRegexp('echo [last]', + '<%s> foo bar baz' % self.nick) + finally: + nickConfig.setValue(orig) + def testMore(self): self.assertRegexp('echo %s' % ('abc'*300), 'more') self.assertRegexp('more', 'more')