sopel/modules/help.py

48 lines
1.2 KiB
Python
Raw Permalink Normal View History

2018-01-18 23:43:27 -05:00
#!/usr/bin/env python3
2017-11-22 19:26:40 -05:00
"""
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)
2017-11-22 19:26:40 -05:00
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)
2017-11-22 19:26:40 -05:00
bot.say(msg)