Added crowdcontrol plugin which allows for kick/ban/warnings based on

regex definitions of unwanted chat messages.
This commit is contained in:
craisins 2014-05-12 20:16:23 -04:00 committed by Ryan Hitchman
parent ebb1c5ed28
commit b0be5e5140
1 changed files with 30 additions and 0 deletions

30
plugins/crowdcontrol.py Normal file
View File

@ -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']