Added the undup filter.

This commit is contained in:
Jeremy Fincher 2004-10-08 16:50:33 +00:00
parent d4b30b6214
commit 2c8490c86a
2 changed files with 17 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class Filter(callbacks.Privmsg):
_filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp',
'scramble', 'morse', 'reverse', 'colorize', 'squish',
'supa1337', 'colorstrip', 'aol', 'rainbow', 'spellit',
'hebrew']
'hebrew', 'undup']
def outfilter(self, irc, msg, args, channel, command):
"""[<channel>] [<command>]
@ -138,6 +138,18 @@ class Filter(callbacks.Privmsg):
irc.reply(text)
squish = wrap(squish, ['text'])
def undup(self, irc, msg, args, text):
"""<text>
Returns <text>, with all consecutive duplicated letters removed.
"""
L = [text[0]]
for c in text:
if c != L[-1]:
L.append(c)
irc.reply(''.join(L))
undup = wrap(undup, ['text'])
def binary(self, irc, msg, args, text):
"""<text>

View File

@ -53,6 +53,10 @@ class FilterTest(ChannelPluginTestCase, PluginDocumentation):
self.assertResponse('squish foo bar baz', 'foobarbaz')
self.assertResponse('squish "foo bar baz"', 'foobarbaz')
def testUndup(self):
self.assertResponse('undup foo bar baz quux', 'fo bar baz qux')
self.assertResponse('undup aaaaaaaaaa', 'a')
def testLithp(self):
self.assertResponse('lithp jamessan', 'jamethan')
self.assertResponse('lithp Shame', 'Thame')