Final cleanups for BadWords kicking.

This commit is contained in:
Jeremy Fincher 2007-09-20 02:24:52 +00:00 committed by James Vega
parent e292c5d0c9
commit f1948a2245
2 changed files with 14 additions and 9 deletions

View File

@ -94,8 +94,10 @@ conf.registerChannelValue(BadWords, 'kick',
registry.Boolean(False, """Determines whether the bot will kick people with
a warning when they use bad words."""))
conf.registerChannelValue(BadWords.kick, 'message',
registry.String("""You have been kicked for using a word prohibited on this
channel. Please use more appropriate language in the future."""))
registry.NormalizedString("""You have been kicked for using a word
prohibited in the presence of this bot. Please use more appropriate
language in the future.""", """Determines the kick message used by the bot
when kicking users for saying bad words."""))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -66,11 +66,14 @@ class BadWords(callbacks.Privmsg):
self.filtering = True
return msg
def updateRegexp(self):
if self.lastModified < self.words.lastModified:
self.makeRegexp(self.words())
self.lastModified = time.time()
def outFilter(self, irc, msg):
if self.filtering and msg.command == 'PRIVMSG':
if self.lastModified < self.words.lastModified:
self.makeRegexp(self.words())
self.lastModified = time.time()
self.updateRegexp()
s = msg.args[1]
if self.registryValue('stripFormatting'):
s = ircutils.stripFormatting(s)
@ -79,17 +82,17 @@ class BadWords(callbacks.Privmsg):
return msg
def doPrivmsg(self, irc, msg):
self.updateRegexp()
s = ircutils.stripFormatting(msg.args[1])
channel = msg.args[0]
if ircutils.isChannel(channel) and self.registryValue('kick', channel):
if self.regexp.match(s):
if self.regexp.search(s):
if irc.nick in irc.state.channels[channel].ops:
message = self.registryValue('kick.message', channel)
irc.queueMsg(ircmsgs.kick(channel, msg.nick, message))
else:
self.log('Should kick %s from %s, but am not opped.',
msg.nick, channel)
callbacks.Privmsg.doPrivmsg(self, irc, msg)
self.log.warning('Should kick %s from %s, but not opped.',
msg.nick, channel)
def makeRegexp(self, iterable):
s = '(%s)' % '|'.join(map(re.escape, iterable))