added cmd_priv dict and made .help only output commands a user can use
This commit is contained in:
parent
a1786b3d85
commit
83889b2941
10
bot.py
10
bot.py
|
@ -72,10 +72,16 @@ class Fulvia(irc.IRCClient):
|
||||||
|
|
||||||
self._commands = {}
|
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.
|
of the function they call.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.cmd_priv = {}
|
||||||
|
"""
|
||||||
|
A dictionary with command names as keys and required privilege
|
||||||
|
levels as values.
|
||||||
|
"""
|
||||||
|
|
||||||
self.doc = {}
|
self.doc = {}
|
||||||
"""
|
"""
|
||||||
A dictionary of command names to their docstring and example, if
|
A dictionary of command names to their docstring and example, if
|
||||||
|
@ -132,6 +138,7 @@ class Fulvia(irc.IRCClient):
|
||||||
self._callables[func.__name__] = func
|
self._callables[func.__name__] = func
|
||||||
for command in func.commands:
|
for command in func.commands:
|
||||||
self._commands[command] = func.__name__
|
self._commands[command] = func.__name__
|
||||||
|
self.cmd_priv[command] = func.priv
|
||||||
|
|
||||||
if func.hook:
|
if func.hook:
|
||||||
self._callables[func.__name__] = func
|
self._callables[func.__name__] = func
|
||||||
|
@ -160,6 +167,7 @@ class Fulvia(irc.IRCClient):
|
||||||
self._callables.pop(func.__name__)
|
self._callables.pop(func.__name__)
|
||||||
for command in func.commands:
|
for command in func.commands:
|
||||||
self._commands.pop(command)
|
self._commands.pop(command)
|
||||||
|
self.cmd_priv.pop(command)
|
||||||
|
|
||||||
if func.hook:
|
if func.hook:
|
||||||
self._callables.pop(func.__name__)
|
self._callables.pop(func.__name__)
|
||||||
|
|
|
@ -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
|
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
|
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.
|
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.
|
limits.
|
||||||
|
|
||||||
Rate-limited functions that use scheduled future commands should import
|
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.
|
If they are not, `message` will be said if given.
|
||||||
"""
|
"""
|
||||||
def actual_decorator(function):
|
def actual_decorator(function):
|
||||||
|
function.priv = 5
|
||||||
|
|
||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def guarded(bot, trigger, *args, **kwargs):
|
def guarded(bot, trigger, *args, **kwargs):
|
||||||
if not trigger.admin:
|
if not trigger.admin:
|
||||||
|
@ -199,6 +201,8 @@ def require_owner(message=None):
|
||||||
If they are not, `message` will be said if given.
|
If they are not, `message` will be said if given.
|
||||||
"""
|
"""
|
||||||
def actual_decorator(function):
|
def actual_decorator(function):
|
||||||
|
function.priv = 10
|
||||||
|
|
||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def guarded(bot, trigger, *args, **kwargs):
|
def guarded(bot, trigger, *args, **kwargs):
|
||||||
if not trigger.owner:
|
if not trigger.owner:
|
||||||
|
|
|
@ -22,12 +22,18 @@ def help(bot, trigger):
|
||||||
ex = random.choice(examples)
|
ex = random.choice(examples)
|
||||||
|
|
||||||
bot.msg(docstring)
|
bot.msg(docstring)
|
||||||
if ex:
|
if ex[0]:
|
||||||
bot.msg("Ex. In: " + ex[0])
|
bot.msg("Ex. In: " + ex[0])
|
||||||
if ex[1]:
|
if ex[1]:
|
||||||
bot.msg("Ex. Out: " + ex[1])
|
bot.msg("Ex. Out: " + ex[1])
|
||||||
|
|
||||||
else:
|
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)
|
msg = "Available commands: " + ", ".join(cmds)
|
||||||
bot.msg(msg)
|
bot.msg(msg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user