add kick/ban/unban helper functions
This commit is contained in:
parent
b0be5e5140
commit
01192e0ddf
13
core/main.py
13
core/main.py
|
@ -35,11 +35,22 @@ class Input(dict):
|
||||||
def notice(msg):
|
def notice(msg):
|
||||||
conn.cmd('NOTICE', [nick, 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,
|
dict.__init__(self, conn=conn, raw=raw, prefix=prefix, command=command,
|
||||||
params=params, nick=nick, user=user, host=host,
|
params=params, nick=nick, user=user, host=host,
|
||||||
paraml=paraml, msg=msg, server=conn.server, chan=chan,
|
paraml=paraml, msg=msg, server=conn.server, chan=chan,
|
||||||
notice=notice, say=say, reply=reply, pm=pm, bot=bot,
|
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
|
# make dict keys accessible as attributes
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
|
|
|
@ -15,16 +15,19 @@ from util import hook
|
||||||
|
|
||||||
|
|
||||||
@hook.regex(r'.*')
|
@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)
|
inp = inp.group(0)
|
||||||
for rule in bot.config.get('crowdcontrol', []):
|
for rule in bot.config.get('crowdcontrol', []):
|
||||||
if re.search(rule['re'], inp) is not None:
|
if re.search(rule['re'], inp) is not None:
|
||||||
if 'ban_length' in rule and rule['ban_length'] != 0:
|
should_kick = rule.get('kick', 0)
|
||||||
conn.cmd("MODE", [chan, "+b", host])
|
ban_length = rule.get('ban_length', 0)
|
||||||
if rule['kick']:
|
reason = rule.get('msg')
|
||||||
conn.cmd('KICK', [chan, nick, rule['msg']])
|
if ban_length != 0:
|
||||||
if 'ban_length' in rule and rule['ban_length'] > 0:
|
ban()
|
||||||
time.sleep(rule['ban_length'])
|
if should_kick:
|
||||||
conn.cmd("MODE", [chan, "-b", host])
|
kick(reason=reason)
|
||||||
if not rule['kick']:
|
elif 'msg' in rule:
|
||||||
return rule['msg']
|
reply(reason)
|
||||||
|
if ban_length > 0:
|
||||||
|
time.sleep(ban_length)
|
||||||
|
unban()
|
||||||
|
|
Loading…
Reference in New Issue