From 1745c6d144d2c11212a2515633dc2a59a6c839a6 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 23 Oct 2004 16:32:59 +0000 Subject: [PATCH] Added shrink filter. --- plugins/Filter.py | 19 +++++++++++++++++++ test/test_Filter.py | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/plugins/Filter.py b/plugins/Filter.py index 7a511fcfc..242da945e 100644 --- a/plugins/Filter.py +++ b/plugins/Filter.py @@ -61,6 +61,10 @@ conf.registerGlobalValue(conf.supybot.plugins.Filter.spellit, conf.registerGlobalValue(conf.supybot.plugins.Filter.spellit, 'replaceNumbers', registry.Boolean(True, """Determines whether or not to replace numbers in the output of spellit.""")) +conf.registerGroup(conf.supybot.plugins.Filter, 'shrink') +conf.registerChannelValue(conf.supybot.plugins.Filter.shrink, 'minimum', + registry.PositiveInteger(4, """Determines the minimum number of a letters + in a word before it will be shrunken by the shrink command/filter.""")) class MyFilterProxy(object): def reply(self, s): @@ -615,6 +619,21 @@ class Filter(callbacks.Privmsg): irc.reply(' '.join(['GNU/' + s for s in text.split()])) gnu = wrap(gnu, ['text']) + def shrink(self, irc, msg, args): + """ + + Returns with each word longer than + supybot.plugins.Filter.shrink.minimum being shrunken (i.e., like + "internationalization" becomes "i18n"). + """ + L = [] + minimum = self.registryValue('shrink.minimum', msg.args[0]) + for word in args: + if len(word) >= minimum: + word = '%s%s%s' % (word[0], len(word)-2, word[-1]) + L.append(word) + irc.reply(' '.join(L)) + Class = Filter diff --git a/test/test_Filter.py b/test/test_Filter.py index 1e81f46e2..f95f7d79f 100644 --- a/test/test_Filter.py +++ b/test/test_Filter.py @@ -157,4 +157,8 @@ class FilterTest(ChannelPluginTestCase, PluginDocumentation): self.assertResponse('echo foo bar baz', 'GNU/foo GNU/bar GNU/baz') self.assertNotError('outfilter') + def testShrink(self): + self.assertResponse('shrink I love you', 'I l2e you') + self.assertResponse('shrink internationalization', 'i18n') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: