Add a censored strings list feature.

Censored strings are defined by a censored_strings array in the config
file. An offending string will be replaced with [censored] in the bot's
output.
This commit is contained in:
Chris Skalenda 2011-01-01 03:01:54 +08:00 committed by rmmh
parent 1295bc6df5
commit d826e2ad83
2 changed files with 24 additions and 3 deletions

View File

@ -8,7 +8,7 @@ def save(conf):
if not os.path.exists('config'): if not os.path.exists('config'):
open('config', 'w').write(inspect.cleandoc( open('config', 'w').write(inspect.cleandoc(
''' r'''
{ {
"connections": "connections":
{ {
@ -21,7 +21,19 @@ if not os.path.exists('config'):
}, },
"disabled_plugins": [], "disabled_plugins": [],
"disabled_commands": [], "disabled_commands": [],
"acls": {} "acls": {},
"censored_strings":
[
"DCC SEND",
"1nj3ct",
"thewrestlinggame",
"startkeylogger",
"hybux",
"\\0",
"\\x01",
"!coz",
"!tell /x"
]
}''') + '\n') }''') + '\n')

View File

@ -16,6 +16,15 @@ def decode(txt):
return txt.decode('utf-8', 'ignore') return txt.decode('utf-8', 'ignore')
def censor(text):
replacement = '[censored]'
if 'censored_strings' in bot.config:
words = map(re.escape, bot.config['censored_strings'])
regex = re.compile('(%s)' % "|".join(words))
text = regex.sub(replacement, text)
return text
class crlf_tcp(object): class crlf_tcp(object):
"Handles tcp connections that consist of utf-8 lines ending with crlf" "Handles tcp connections that consist of utf-8 lines ending with crlf"
@ -181,7 +190,7 @@ class IRC(object):
def cmd(self, command, params=None): def cmd(self, command, params=None):
if params: if params:
params[-1] = ':' + params[-1] params[-1] = ':' + params[-1]
self.send(command + ' ' + ' '.join(params)) self.send(command + ' ' + ' '.join(map(censor, params)))
else: else:
self.send(command) self.send(command)