From 09a4f03f4cda04d0f0478adb6a07f191db6f9760 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 25 May 2018 12:54:11 -0400 Subject: [PATCH] @require_privilege sets func.priv --- bot.py | 2 +- module.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 6a45d3f..6b77d31 100755 --- a/bot.py +++ b/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 diff --git a/module.py b/module.py index 50cc569..8ca17a9 100755 --- a/module.py +++ b/module.py @@ -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):