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 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 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.""")) 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): class Misc(callbacks.Privmsg):
def __init__(self): def __init__(self):
@ -488,16 +498,28 @@ class Misc(callbacks.Privmsg):
iterable.next() # Drop the first message. iterable.next() # Drop the first message.
predicates = list(utils.flatten(predicates.itervalues())) predicates = list(utils.flatten(predicates.itervalues()))
resp = [] resp = []
if irc.nested and not \
self.registryValue('last.nested.includeTimestamp'):
tsf = None
else:
tsf = self.registryValue('timestampFormat') tsf = self.registryValue('timestampFormat')
if irc.nested and not self.registryValue('last.nested.includeNick'):
showNick = False
else:
showNick = True
for m in iterable: for m in iterable:
for predicate in predicates: for predicate in predicates:
if not predicate(m): if not predicate(m):
break break
else: else:
if nolimit: if nolimit:
resp.append(ircmsgs.prettyPrint(m, timestampFormat=tsf)) resp.append(ircmsgs.prettyPrint(m,
timestampFormat=tsf,
showNick=showNick))
else: else:
irc.reply(ircmsgs.prettyPrint(m, timestampFormat=tsf)) irc.reply(ircmsgs.prettyPrint(m,
timestampFormat=tsf,
showNick=showNick))
return return
if not resp: if not resp:
irc.error('I couldn\'t find a message matching that criteria in ' 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') L.append('</msg>\n')
return ''.join(L) 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. """Provides a client-friendly string form for messages.
IIRC, I copied BitchX's (or was it XChat's?) format 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]) m = _unactionre.match(msg.args[1])
if m: if m:
s = '* %s %s' % (nick(), m.group(1)) s = '* %s %s' % (nick(), m.group(1))
else:
if not showNick:
s = '%s' % msg.args[1]
else: else:
s = '<%s> %s' % (nick(), msg.args[1]) s = '<%s> %s' % (nick(), msg.args[1])
elif msg.command == 'NOTICE': elif msg.command == 'NOTICE':
if not showNick:
s = '%s' % msg.args[1]
else:
s = '-%s- %s' % (nick(), msg.args[1]) s = '-%s- %s' % (nick(), msg.args[1])
elif msg.command == 'JOIN': elif msg.command == 'JOIN':
s = '*** %s has joined %s' % (msg.nick, msg.args[0]) 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) s = '*** %s has quit IRC%s' % (msg.nick, quitmsg)
elif msg.command == 'TOPIC': elif msg.command == 'TOPIC':
s = '*** %s changes topic to %s' % (nickorprefix(), msg.args[1]) s = '*** %s changes topic to %s' % (nickorprefix(), msg.args[1])
at = getattr(msg, 'receivedAt', False) at = getattr(msg, 'receivedAt', None)
if timestampFormat and at: if timestampFormat and at:
s = '%s %s' % (time.strftime(timestampFormat, time.localtime(at)), s) s = '%s %s' % (time.strftime(timestampFormat, time.localtime(at)), s)
return s return s

View File

@ -188,6 +188,28 @@ class MiscTestCase(ChannelPluginTestCase):
finally: finally:
conf.supybot.plugins.Misc.timestampFormat.setValue(orig) 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): def testMore(self):
self.assertRegexp('echo %s' % ('abc'*300), 'more') self.assertRegexp('echo %s' % ('abc'*300), 'more')
self.assertRegexp('more', 'more') self.assertRegexp('more', 'more')