mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Added new behavior for Misc.last when nested - can optionally exclude the nick
and timestamp
This commit is contained in:
parent
bdca894522
commit
d4b30b6214
28
src/Misc.py
28
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 '
|
||||
|
@ -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.
|
||||
@ -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
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user