From 83889b2941a740c2c58331f792a6c50627d55a9b Mon Sep 17 00:00:00 2001 From: iou1name Date: Sun, 25 Mar 2018 14:26:29 -0400 Subject: [PATCH] added cmd_priv dict and made .help only output commands a user can use --- bot.py | 10 +++++++++- module.py | 6 +++++- modules/help.py | 10 ++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index c622575..d45a8aa 100755 --- a/bot.py +++ b/bot.py @@ -72,10 +72,16 @@ class Fulvia(irc.IRCClient): self._commands = {} """ - A dictionary containing all all commands to look for and the name + A dictionary containingv all commands to look for and the name of the function they call. """ + self.cmd_priv = {} + """ + A dictionary with command names as keys and required privilege + levels as values. + """ + self.doc = {} """ A dictionary of command names to their docstring and example, if @@ -132,6 +138,7 @@ class Fulvia(irc.IRCClient): self._callables[func.__name__] = func for command in func.commands: self._commands[command] = func.__name__ + self.cmd_priv[command] = func.priv if func.hook: self._callables[func.__name__] = func @@ -160,6 +167,7 @@ class Fulvia(irc.IRCClient): self._callables.pop(func.__name__) for command in func.commands: self._commands.pop(command) + self.cmd_priv.pop(command) if func.hook: self._callables.pop(func.__name__) diff --git a/module.py b/module.py index 211fa8b..50cc569 100755 --- a/module.py +++ b/module.py @@ -86,7 +86,7 @@ def rate(user=0, channel=0, server=0): basis, in a channel, or across the server (bot). A value of zero means no limit. If a function is given a rate of 20, that function may only be used once every 20 seconds in the scope corresponding to the parameter. - Users on the admin list in Sopel’s configuration are exempted from rate + Users on the admin list in Fulvia's configuration are exempted from rate limits. Rate-limited functions that use scheduled future commands should import @@ -178,6 +178,8 @@ def require_admin(message=None): If they are not, `message` will be said if given. """ def actual_decorator(function): + function.priv = 5 + @functools.wraps(function) def guarded(bot, trigger, *args, **kwargs): if not trigger.admin: @@ -199,6 +201,8 @@ def require_owner(message=None): If they are not, `message` will be said if given. """ def actual_decorator(function): + function.priv = 10 + @functools.wraps(function) def guarded(bot, trigger, *args, **kwargs): if not trigger.owner: diff --git a/modules/help.py b/modules/help.py index 922e0c4..568ea53 100755 --- a/modules/help.py +++ b/modules/help.py @@ -22,12 +22,18 @@ def help(bot, trigger): ex = random.choice(examples) bot.msg(docstring) - if ex: + if ex[0]: bot.msg("Ex. In: " + ex[0]) if ex[1]: bot.msg("Ex. Out: " + ex[1]) else: - cmds = sorted(bot.doc.keys()) + if not trigger.admin and not trigger.owner: + cmds = [cmd for cmd, priv in bot.cmd_priv.items() if priv < 5] + elif trigger.admin and not trigger.owner: + cmds = [cmd for cmd, priv in bot.cmd_priv.items() if priv <= 5] + else: + cmds = bot.cmd_priv.keys() + cmds = sorted(cmds) msg = "Available commands: " + ", ".join(cmds) bot.msg(msg)