diff --git a/plugins/BadWords.py b/plugins/BadWords.py index 868e512ea..4f7d9615b 100644 --- a/plugins/BadWords.py +++ b/plugins/BadWords.py @@ -66,15 +66,16 @@ class LastModifiedSetOfStrings(registry.SpaceSeparatedListOfStrings): lastModified = 0 def setValue(self, v): self.lastModified = time.time() - registry.SpaceSeparatedSetOfStrings.setValue(self, v) + registry.SpaceSeparatedListOfStrings.setValue(self, v) conf.registerPlugin('BadWords') conf.registerChannelValue(conf.supybot.plugins.BadWords, 'words', - registry.SpaceSeparatedListOfStrings([], """Determines what words are + LastModifiedSetOfStrings([], """Determines what words are considered to be 'bad' so the bot won't say them.""")) class BadWords(privmsgs.CapabilityCheckingPrivmsg): priority = 1 + capability = 'admin' def __init__(self): privmsgs.CapabilityCheckingPrivmsg.__init__(self) self.lastModified = 0 @@ -94,6 +95,27 @@ class BadWords(privmsgs.CapabilityCheckingPrivmsg): def makeRegexp(self, iterable): self.regexp = re.compile(r'\b('+'|'.join(iterable)+r')\b', re.I) + def add(self, irc, msg, args): + """ [ ...] + + Adds all s to the list of words the bot isn't to say. + """ + set = self.words() + set.update(args) + self.words.setValue(set) + irc.replySuccess() + + def remove(self, irc, msg, args): + """ [ ...] + + Removes a s from the list of words the bot isn't to say. + """ + set = self.words() + for word in args: + set.discard(word) + self.words.setValue(set) + irc.replySuccess() + Class = BadWords diff --git a/test/test_BadWords.py b/test/test_BadWords.py index 5b5f368c3..54014db78 100644 --- a/test/test_BadWords.py +++ b/test/test_BadWords.py @@ -34,6 +34,10 @@ from testsupport import * class BadWordsTestCase(PluginTestCase, PluginDocumentation): plugins = ('BadWords', 'Utilities') badwords = ('shit', 'ass') + def tearDown(self): + default = conf.supybot.plugins.BadWords.words.default + conf.supybot.plugins.BadWords.words.setValue(default) + def _test(self): for word in self.badwords: self.assertRegexp('echo %s' % word, '(?!%s)' % word)