2018-03-16 03:13:43 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Displays help docs and examples for commands, as well as lists all commands
|
|
|
|
available.
|
|
|
|
"""
|
|
|
|
import random
|
|
|
|
|
|
|
|
from module import commands, example
|
|
|
|
|
|
|
|
@commands('help', 'commands')
|
|
|
|
@example('.help tell')
|
|
|
|
def help(bot, trigger):
|
|
|
|
"""Shows a command's documentation, and possibly an example."""
|
|
|
|
if trigger.group(2):
|
|
|
|
name = trigger.group(2)
|
|
|
|
name = name.lower()
|
2018-05-25 11:53:15 -04:00
|
|
|
if name not in bot.commands:
|
2018-05-29 13:59:38 -04:00
|
|
|
return bot.msg("Command not found.")
|
2018-05-25 13:46:43 -04:00
|
|
|
cmd = bot.commands[name]
|
|
|
|
docstring, examples = cmd.doc
|
2018-03-16 03:13:43 -04:00
|
|
|
if examples:
|
|
|
|
ex = random.choice(examples)
|
|
|
|
|
|
|
|
bot.msg(docstring)
|
2018-05-25 13:46:43 -04:00
|
|
|
if cmd.aliases:
|
|
|
|
bot.msg("Aliases: " + ", ".join(cmd.aliases))
|
2018-03-25 14:26:29 -04:00
|
|
|
if ex[0]:
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.msg("Ex. In: " + ex[0])
|
2018-05-25 13:46:43 -04:00
|
|
|
if ex[1]:
|
|
|
|
bot.msg("Ex. Out: " + ex[1])
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
else:
|
2018-05-25 11:53:15 -04:00
|
|
|
if trigger.owner:
|
|
|
|
cmds = [cmd for _, cmd in bot.commands.items()]
|
|
|
|
elif trigger.admin:
|
|
|
|
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= 5]
|
2018-03-25 14:26:29 -04:00
|
|
|
else:
|
2018-05-27 20:01:04 -04:00
|
|
|
priv = bot.channels[trigger.channel].privileges[trigger.nick]
|
|
|
|
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv <= priv]
|
2018-05-25 11:53:15 -04:00
|
|
|
|
2018-05-25 13:46:43 -04:00
|
|
|
cmds = [cmd.name for cmd in cmds if cmd.canonical]
|
2018-03-25 14:26:29 -04:00
|
|
|
cmds = sorted(cmds)
|
2018-03-16 03:13:43 -04:00
|
|
|
msg = "Available commands: " + ", ".join(cmds)
|
|
|
|
bot.msg(msg)
|