This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/core_sieve.py

61 lines
2.0 KiB
Python
Raw Permalink Normal View History

2011-11-20 10:23:31 +01:00
import re
2014-02-14 04:36:57 +01:00
from fnmatch import fnmatch
2011-11-20 10:23:31 +01:00
from util import hook
2011-11-20 10:23:31 +01:00
@hook.sieve
def sieve_suite(bot, input, func, kind, args):
if input.command == 'PRIVMSG' and \
input.nick.endswith('bot') and args.get('ignorebots', True):
return None
2011-11-20 10:23:31 +01:00
if kind == "command":
if input.trigger in bot.config.get('disabled_commands', []):
return None
fn = re.match(r'^plugins.(.+).py$', func._filename)
disabled = bot.config.get('disabled_plugins', [])
if fn and fn.group(1).lower() in disabled:
return None
acl = bot.config.get('acls', {}).get(func.__name__)
if acl:
if 'deny-except' in acl:
allowed_channels = map(unicode.lower, acl['deny-except'])
if input.chan.lower() not in allowed_channels:
return None
if 'allow-except' in acl:
denied_channels = map(unicode.lower, acl['allow-except'])
if input.chan.lower() in denied_channels:
return None
2013-08-01 09:07:16 +02:00
# shim so plugins using the old "adminonly" permissions format still work
2011-11-20 10:23:31 +01:00
if args.get('adminonly', False):
2013-08-05 01:16:06 +02:00
args["permissions"] = ["adminonly"]
2011-11-20 10:23:31 +01:00
2013-08-01 09:07:16 +02:00
if args.get('permissions', False):
groups = bot.config.get("permissions", [])
2013-08-01 09:07:16 +02:00
allowed_permissions = args.get('permissions', [])
2013-11-27 12:17:04 +01:00
mask = input.mask.lower()
2013-08-01 09:07:16 +02:00
# loop over every group
2013-11-27 12:17:04 +01:00
for key, group in groups.iteritems():
2013-08-01 09:07:16 +02:00
# loop over every permission the command allows
for permission in allowed_permissions:
# see if the group has that permission
2013-11-27 12:17:04 +01:00
if permission in group["perms"]:
# if so, check it
group_users = [_mask.lower() for _mask in group["users"]]
for pattern in group_users:
if fnmatch(mask, pattern):
print "Allowed group {}.".format(group)
return input
2013-08-01 09:07:16 +02:00
input.notice("Sorry, you are not allowed to use this command.")
return None
2011-11-20 10:23:31 +01:00
return input