Added a list command.

This commit is contained in:
Jeremy Fincher 2004-07-20 06:37:21 +00:00
parent 6287713fcd
commit 1cc62cf609
3 changed files with 31 additions and 5 deletions

View File

@ -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.

View File

@ -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):
"""<word> [<word> ...]

View File

@ -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: