@require_privilege sets func.priv
This commit is contained in:
parent
5a7d90b0ba
commit
09a4f03f4c
2
bot.py
2
bot.py
|
@ -203,7 +203,7 @@ class Fulvia(irc.IRCClient):
|
|||
or users alike.
|
||||
"""
|
||||
func_names = []
|
||||
if message.startswith(self.prefix):
|
||||
if message.startswith(self.prefix) and message != self.prefix:
|
||||
command, _, _ = message.partition(" ")
|
||||
command = command.replace(self.prefix, "", 1)
|
||||
func_name = self.commands.get(command)._func_name
|
||||
|
|
|
@ -154,13 +154,17 @@ 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):
|
||||
@functools.wraps(function)
|
||||
def guarded(bot, trigger, *args, **kwargs):
|
||||
# If this is a privmsg, ignore privilege requirements
|
||||
if trigger.is_privmsg or trigger.admin:
|
||||
return function(bot, trigger, *args, **kwargs)
|
||||
channel_privs = bot.privileges[trigger.channel]
|
||||
channel_privs = bot.channels[trigger.channel].privileges
|
||||
allowed = channel_privs.get(trigger.nick, 0) >= level
|
||||
if not allowed:
|
||||
if message and not callable(message):
|
||||
|
@ -168,7 +172,7 @@ def require_privilege(level, message=None):
|
|||
else:
|
||||
return function(bot, trigger, *args, **kwargs)
|
||||
return guarded
|
||||
return actual_decorator
|
||||
return add_attribute(actual_decorator)
|
||||
|
||||
|
||||
def require_admin(message=None):
|
||||
|
|
Loading…
Reference in New Issue
Block a user