diff --git a/core/config.py b/core/config.py index abd064a..0649b50 100644 --- a/core/config.py +++ b/core/config.py @@ -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') diff --git a/core/irc.py b/core/irc.py index 6f88631..a5f3567 100644 --- a/core/irc.py +++ b/core/irc.py @@ -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)