From b0be5e51407ad852e08fe86cea7264eaff32f063 Mon Sep 17 00:00:00 2001 From: craisins Date: Mon, 12 May 2014 20:16:23 -0400 Subject: [PATCH] Added crowdcontrol plugin which allows for kick/ban/warnings based on regex definitions of unwanted chat messages. --- plugins/crowdcontrol.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 plugins/crowdcontrol.py diff --git a/plugins/crowdcontrol.py b/plugins/crowdcontrol.py new file mode 100644 index 0000000..19937f6 --- /dev/null +++ b/plugins/crowdcontrol.py @@ -0,0 +1,30 @@ +# crowdcontrol.py by craisins in 2014 +# Bot must have some sort of op or admin privileges to be useful + +import re +import time +from util import hook + +# Use "crowdcontrol" array in config +# syntax +# rule: +# re: RegEx. regular expression to match +# msg: String. message to display either with kick or as a warning +# kick: Integer. 1 for True, 0 for False on if to kick user +# ban_length: Integer. (optional) Length of time (seconds) to ban user. (-1 to never unban, 0 to not ban, > 1 for time) + + +@hook.regex(r'.*') +def crowdcontrol(inp, nick='', chan='', host='', bot=None, conn=None): + inp = inp.group(0) + for rule in bot.config.get('crowdcontrol', []): + if re.search(rule['re'], inp) is not None: + if 'ban_length' in rule and rule['ban_length'] != 0: + conn.cmd("MODE", [chan, "+b", host]) + if rule['kick']: + conn.cmd('KICK', [chan, nick, rule['msg']]) + if 'ban_length' in rule and rule['ban_length'] > 0: + time.sleep(rule['ban_length']) + conn.cmd("MODE", [chan, "-b", host]) + if not rule['kick']: + return rule['msg']