simple acls (deny-except and allow-except), force config rewrite on start
This commit is contained in:
parent
26515cf14b
commit
7663b3e5d3
|
@ -21,7 +21,7 @@ if not os.path.exists('config'):
|
||||||
del conf
|
del conf
|
||||||
|
|
||||||
bot.config = yaml.load(open('config'))
|
bot.config = yaml.load(open('config'))
|
||||||
bot._config_dirty = False
|
bot._config_dirty = True # force a rewrite on start
|
||||||
bot._config_mtime = os.stat('config').st_mtime
|
bot._config_mtime = os.stat('config').st_mtime
|
||||||
|
|
||||||
def config_dirty(self):
|
def config_dirty(self):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from util import hook
|
from util import hook
|
||||||
|
@ -16,14 +17,28 @@ def sieve_suite(bot, input, func, args):
|
||||||
hook = args.get('hook', r'(.*)')
|
hook = args.get('hook', r'(.*)')
|
||||||
|
|
||||||
if args.get('prefix', True):
|
if args.get('prefix', True):
|
||||||
# add a prefix, unless it's a private message
|
if input.chan == input.nick: # private message, prefix not required
|
||||||
hook = (r'^(?:[.!]|' if input.chan != input.nick else r'^(?:[.!]?|') \
|
prefix = r'^(?:[.!]?|'
|
||||||
+ input.conn.nick + r'[:,]*\s*)' + hook
|
else:
|
||||||
|
prefix = r'^(?:[.!]|'
|
||||||
|
hook = prefix + input.conn.nick + r'[:,]*\s)' + hook
|
||||||
|
|
||||||
input.re = re.match(hook, input.msg, flags=re.I)
|
input.re = re.match(hook, input.msg, flags=re.I)
|
||||||
if input.re is None:
|
if input.re is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
acl = bot.config.get('acls', {}).get(func.__name__)
|
||||||
|
if acl:
|
||||||
|
print acl
|
||||||
|
if 'deny-except' in acl:
|
||||||
|
allowed_channels = map(str.lower, acl['deny-except'])
|
||||||
|
if input.chan.lower() not in allowed_channels:
|
||||||
|
return None
|
||||||
|
if 'allow-except' in acl:
|
||||||
|
denied_channels = map(str.lower, acl['allow-except'])
|
||||||
|
if input.chan.lower() in denied_channels:
|
||||||
|
return None
|
||||||
|
|
||||||
input.inp_unstripped = ' '.join(input.re.groups())
|
input.inp_unstripped = ' '.join(input.re.groups())
|
||||||
input.inp = input.inp_unstripped.strip()
|
input.inp = input.inp_unstripped.strip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue