40 lines
982 B
Python
Executable File
40 lines
982 B
Python
Executable File
#!/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()
|
|
if name not in bot.doc:
|
|
return
|
|
doc = bot.doc[name]
|
|
docstring, examples = doc
|
|
if examples:
|
|
ex = random.choice(examples)
|
|
|
|
bot.msg(docstring)
|
|
if ex[0]:
|
|
bot.msg("Ex. In: " + ex[0])
|
|
if ex[1]:
|
|
bot.msg("Ex. Out: " + ex[1])
|
|
|
|
else:
|
|
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)
|