@require_privilege actually sets func.priv this time
This commit is contained in:
parent
b8bbcd4971
commit
0f65440fd5
|
@ -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
|
user does not have the privilege, `message` will be said if given. If it is
|
||||||
a private message, no checking will be done.
|
a private message, no checking will be done.
|
||||||
"""
|
"""
|
||||||
def add_attribute(function):
|
|
||||||
function.priv = level
|
|
||||||
return add_attribute
|
|
||||||
|
|
||||||
def actual_decorator(function):
|
def actual_decorator(function):
|
||||||
|
function.priv = level
|
||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def guarded(bot, trigger, *args, **kwargs):
|
def guarded(bot, trigger, *args, **kwargs):
|
||||||
# If this is a privmsg, ignore privilege requirements
|
# If this is a privmsg, ignore privilege requirements
|
||||||
|
@ -172,7 +169,7 @@ def require_privilege(level, message=None):
|
||||||
else:
|
else:
|
||||||
return function(bot, trigger, *args, **kwargs)
|
return function(bot, trigger, *args, **kwargs)
|
||||||
return guarded
|
return guarded
|
||||||
return add_attribute(actual_decorator)
|
return actual_decorator
|
||||||
|
|
||||||
|
|
||||||
def require_admin(message=None):
|
def require_admin(message=None):
|
||||||
|
@ -252,3 +249,4 @@ def url_callback(url):
|
||||||
function.url_callback.append(url)
|
function.url_callback.append(url)
|
||||||
return function
|
return function
|
||||||
return add_attribute
|
return add_attribute
|
||||||
|
|
|
@ -35,7 +35,8 @@ def help(bot, trigger):
|
||||||
elif trigger.admin:
|
elif trigger.admin:
|
||||||
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= 5]
|
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= 5]
|
||||||
else:
|
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 = [cmd.name for cmd in cmds if cmd.canonical]
|
||||||
cmds = sorted(cmds)
|
cmds = sorted(cmds)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user