48 lines
1.2 KiB
Python
Executable File
48 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
help.py - Sopel Help Module
|
|
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
Copyright © 2013, Elad Alfassa, <elad@fedoraproject.org>
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
http://sopel.chat
|
|
"""
|
|
from module import commands, rule, example, priority
|
|
|
|
@rule('$nick' '(?i)(help|doc) +([A-Za-z]+)(?:\?+)?$')
|
|
@example('.help tell')
|
|
@commands('help', 'commands')
|
|
@priority('low')
|
|
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
|
|
newlines = ['']
|
|
lines = list(filter(None, bot.doc[name][0]))
|
|
lines = list(map(str.strip, lines))
|
|
for line in lines:
|
|
newlines[-1] = newlines[-1] + ' ' + line
|
|
if line[-1] is '.':
|
|
newlines.append('')
|
|
newlines = list(map(str.strip, newlines))
|
|
if bot.doc[name][1]:
|
|
newlines.append('Ex. ' + bot.doc[name][1])
|
|
|
|
for msg in newlines:
|
|
bot.say(msg)
|
|
else:
|
|
command_groups = list(bot.command_groups.values())
|
|
commands = []
|
|
for group in command_groups:
|
|
if type(group) == list:
|
|
commands += group
|
|
else:
|
|
commands += [group]
|
|
commands.sort()
|
|
msg = "Available commands: " + ', '.join(commands)
|
|
bot.say(msg)
|