add kick/ban/unban helper functions

This commit is contained in:
Ryan Hitchman 2014-05-12 22:33:47 -07:00
parent b0be5e5140
commit 01192e0ddf
2 changed files with 25 additions and 11 deletions

View File

@ -35,11 +35,22 @@ class Input(dict):
def notice(msg):
conn.cmd('NOTICE', [nick, msg])
def kick(target=None, reason=None):
conn.cmd('KICK', [chan, target or nick, reason or ''])
def ban(target=None):
conn.cmd('MODE', [chan, '+b', target or host])
def unban(target=None):
conn.cmd('MODE', [chan, '-b', target or host])
dict.__init__(self, conn=conn, raw=raw, prefix=prefix, command=command,
params=params, nick=nick, user=user, host=host,
paraml=paraml, msg=msg, server=conn.server, chan=chan,
notice=notice, say=say, reply=reply, pm=pm, bot=bot,
me=me, set_nick=set_nick, lastparam=paraml[-1])
kick=kick, ban=ban, unban=unban, me=me,
set_nick=set_nick, lastparam=paraml[-1])
# make dict keys accessible as attributes
def __getattr__(self, key):

View File

@ -15,16 +15,19 @@ from util import hook
@hook.regex(r'.*')
def crowdcontrol(inp, nick='', chan='', host='', bot=None, conn=None):
def crowdcontrol(inp, kick=None, ban=None, unban=None, reply=None, bot=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']
should_kick = rule.get('kick', 0)
ban_length = rule.get('ban_length', 0)
reason = rule.get('msg')
if ban_length != 0:
ban()
if should_kick:
kick(reason=reason)
elif 'msg' in rule:
reply(reason)
if ban_length > 0:
time.sleep(ban_length)
unban()