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

View File

@ -16,6 +16,15 @@ def decode(txt):
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):
"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):
if params:
params[-1] = ':' + params[-1]
self.send(command + ' ' + ' '.join(params))
self.send(command + ' ' + ' '.join(map(censor, params)))
else:
self.send(command)