52 lines
1.3 KiB
Python
Executable File
52 lines
1.3 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
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 __future__ import unicode_literals, absolute_import, print_function, division
|
|
|
|
import textwrap
|
|
import collections
|
|
import json
|
|
|
|
from logger import get_logger
|
|
from module import commands, rule, example, priority
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
@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 in bot.doc:
|
|
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:
|
|
helps = list(bot.command_groups)
|
|
helps.sort()
|
|
msg = "Available commands: " + ', '.join(helps)
|
|
bot.say(msg)
|