Added new behavior for Misc.last when nested - can optionally exclude the nick

and timestamp
This commit is contained in:
Daniel DiPaolo 2004-10-08 16:00:51 +00:00
parent bdca894522
commit d4b30b6214
3 changed files with 57 additions and 7 deletions

View File

@ -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 = []
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 '

View File

@ -267,7 +267,7 @@ def toXml(msg, pretty=True, includeTime=True):
L.append('</msg>\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.
@ -283,9 +283,15 @@ def prettyPrint(msg, addRecipients=False, timestampFormat=None):
m = _unactionre.match(msg.args[1])
if m:
s = '* %s %s' % (nick(), m.group(1))
else:
if not showNick:
s = '%s' % msg.args[1]
else:
s = '<%s> %s' % (nick(), msg.args[1])
elif msg.command == 'NOTICE':
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])
@ -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

View File

@ -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')