added cmd_priv dict and made .help only output commands a user can use

This commit is contained in:
iou1name 2018-03-25 14:26:29 -04:00
parent a1786b3d85
commit 83889b2941
3 changed files with 22 additions and 4 deletions

10
bot.py
View File

@ -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__)

View File

@ -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 Sopels 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:

View File

@ -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)