rendered paste bodyimport timeimport supybot.utils as utilsfrom supybot.commands import *import supybot.plugins as pluginsimport supybot.ircutils as ircutilsimport supybot.schedule as schedulefrom supybot.ircmsgs import kick, ban, unbanimport supybot.callbacks as callbacksimport reclass NoSwear(callbacks.Plugin): """Add the help for "@plugin help NoSwear" here This should describe *how* to use this plugin.""" regexps = ['swearWordSnarfer'] #regex = re.compile(r"(\bfuck\b|\bnigga\b|\bnigger\b|\bshit\b|\bdick\b|\bcunt\b|\bvagina\b|\banus\b|\bbum.*\bhole\b|\borfice\b|\bcum\b|\b(\s\b|\b^)idiot\b|\bfagot\b|\bfaggot\b|\bpenis\b|\bwanker\b|\bf\*ck\b|\bsh\*t\b|\bwtf\b|\bw.t.f\b|\bfuck.n|\bass...+\b)") badWords = ['f[*u]ck(ing?)?', 'sh[*i]t', 'cunt', 'an.s', 'bum[^A-Z,a-z]*hole', 'orfice', 'cum', 'fagg?.t', 'pen.s', 'wank(a|er)', 'fuck.n', 'arse', '(ass|arse)(wipe|hole)'] badLetters = ['fuck', 'nigga', 'nigger', 'vagina'] _fnUser = re.compile(r'^(?:n|i)=') _regex = None @property def regex(self): """ Builds and caches the great regex """ if self._regex is None: r = [] for word in self.badWords: r.append(r'((\W|\b)%s(\W|\b))|' % word) for ltrs in self.badLetters: r.append(r'(%s)|' % ltrs) self._regexString = '.*(' + ((''.join(r))[:-1]) + ').*' self._regex = re.compile(self._regexString) # Remove the last | return self._regex def doPrivmsg(self, irc, msg): channel, text = msg.args text = text.lower() if '#' in channel: #print self.regex #irc.reply('testing %s against %s' % (text, self._regexString)) if self.regex.match(text): try: hostmask = irc.state.nickToHostmask(msg.nick) except KeyError: return (nick, user, host) = ircutils.splitHostmask(hostmask) user = self._fnUser.sub('*', user) banmask = ircutils.joinHostmask('*', user, msg.host) if ircutils.hostmaskPatternEqual(banmask, irc.prefix): return irc.queueMsg(ban(channel, banmask, 'For swearing. 5 minute timeout')) irc.queueMsg(kick(channel, msg.nick, 'For swearing')) def unBan(): if channel in irc.state.channels and \ banmask in irc.state.channels[channel].bans: irc.queueMsg(unban(channel, banmask)) schedule.addEvent(unBan, time.time()+300) elif 'fag' in text.split(): try: hostmask = irc.state.nickToHostmask(msg.nick) except KeyError: return (nick, user, host) = ircutils.splitHostmask(hostmask) irc.reply('No thanks %s I don\'t smoke' % user) return msgClass = NoSwear# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: