@require_privilege actually sets func.priv this time

This commit is contained in:
iou1name 2018-05-27 20:01:04 -04:00
parent b8bbcd4971
commit 0f65440fd5
2 changed files with 5 additions and 6 deletions

View File

@ -154,11 +154,8 @@ def require_privilege(level, message=None):
user does not have the privilege, `message` will be said if given. If it is
a private message, no checking will be done.
"""
def add_attribute(function):
function.priv = level
return add_attribute
def actual_decorator(function):
function.priv = level
@functools.wraps(function)
def guarded(bot, trigger, *args, **kwargs):
# If this is a privmsg, ignore privilege requirements
@ -172,7 +169,7 @@ def require_privilege(level, message=None):
else:
return function(bot, trigger, *args, **kwargs)
return guarded
return add_attribute(actual_decorator)
return actual_decorator
def require_admin(message=None):
@ -252,3 +249,4 @@ def url_callback(url):
function.url_callback.append(url)
return function
return add_attribute

View File

@ -35,7 +35,8 @@ def help(bot, trigger):
elif trigger.admin:
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= 5]
else:
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv < 5]
priv = bot.channels[trigger.channel].privileges[trigger.nick]
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= priv]
cmds = [cmd.name for cmd in cmds if cmd.canonical]
cmds = sorted(cmds)