diff --git a/ChangeLog b/ChangeLog index c88ae778a..b52ac407f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Added BadWords.list, to list the bad words currently being + censored by the bot. + * Changed Misc.help to allow plugins to specify their own help, and added help for several of the more confusing plugins. diff --git a/plugins/BadWords.py b/plugins/BadWords.py index 9f81fff5e..aff7e94d7 100644 --- a/plugins/BadWords.py +++ b/plugins/BadWords.py @@ -107,6 +107,7 @@ class BadWords(privmsgs.CapabilityCheckingPrivmsg): capability = 'admin' def __init__(self): privmsgs.CapabilityCheckingPrivmsg.__init__(self) + self.filtering = True self.lastModified = 0 self.words = conf.supybot.plugins.BadWords.words @@ -117,17 +118,20 @@ class BadWords(privmsgs.CapabilityCheckingPrivmsg): elif replaceMethod == 'nastyCharacters': return self.registryValue('nastyChars')[:len(m.group(1))] + def inFilter(self, irc, msg): + self.filtering = True + return msg + def outFilter(self, irc, msg): - if msg.command == 'PRIVMSG': + if self.filtering and msg.command == 'PRIVMSG': if self.lastModified < self.words.lastModified: self.makeRegexp(self.words()) self.lastModified = time.time() s = msg.args[1] s = ircutils.stripFormatting(s) s = self.regexp.sub(self.sub, s) - return ircmsgs.privmsg(msg.args[0], s) - else: - return msg + msg = ircmsgs.privmsg(msg.args[0], s) + return msg def makeRegexp(self, iterable): s = '(%s)' % '|'.join(map(re.escape, iterable)) @@ -135,6 +139,19 @@ class BadWords(privmsgs.CapabilityCheckingPrivmsg): s = r'\b%s\b' % s self.regexp = re.compile(s, re.I) + def list(self, irc, msg, args): + """takes no arguments + + Returns the list of words being censored. + """ + L = list(self.words()) + if L: + self.filtering = False + utils.sortBy(str.lower, L) + irc.reply(utils.commaAndify(L)) + else: + irc.reply('I\'m not currently censoring any bad words.') + def add(self, irc, msg, args): """ [ ...] diff --git a/test/test_BadWords.py b/test/test_BadWords.py index ce9593eff..5366c5886 100644 --- a/test/test_BadWords.py +++ b/test/test_BadWords.py @@ -31,7 +31,7 @@ from testsupport import * -class BadWordsTestCase(PluginTestCase, PluginDocumentation): +class BadWordsTestCase(PluginTestCase): plugins = ('BadWords', 'Utilities') badwords = ('shit', 'ass') def tearDown(self): @@ -64,5 +64,11 @@ class BadWordsTestCase(PluginTestCase, PluginDocumentation): self.assertNotError('badwords remove %s' % ' '.join(self.badwords)) self._NegTest() + def testList(self): + self.assertNotError('badwords list') + self.assertNotError('badwords add shit') + self.assertNotError('badwords add ass') + self.assertResponse('badwords list', 'ass and shit') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: