@rule(u'$nick(?i)(help|doc) +([A-Za-z]+)(?:\\?+)?$')
@example(u'.help tell')
@commands(u'help', u'commands')
@priority(u'low')
def help(bot, trigger):
 if trigger.group(2):
  name = trigger.group(2)
  name = name.lower()
  threshold = 3
  if (name in bot.doc):
   if ((len(bot.doc[name][0]) + (1 if bot.doc[name][1] else 0)) > threshold):
    if (trigger.nick != trigger.sender):
     bot.reply(u"The documentation for this command is too long; I'm sending it to you in a private message.")
    msgfun = (lambda l: bot.msg(trigger.nick, l))
   else:
    msgfun = bot.reply
   for line in bot.doc[name][0]:
    msgfun(line)
   if bot.doc[name][1]:
    msgfun((u'e.g. ' + bot.doc[name][1]))
 else:
  if ((u'command-gist' in bot.memory) and (bot.memory[u'command-gist'][0] == len(bot.command_groups))):
   url = bot.memory[u'command-gist'][1]
  else:
   bot.say(u"Hang on, I'm creating a list.")
   msgs = []
   name_length = max(6, max((len(k) for k in bot.command_groups.keys())))
   for (category, cmds) in collections.OrderedDict(sorted(bot.command_groups.items())).items():
    category = category.upper().ljust(name_length)
    cmds = u'  '.join(cmds)
    msg = ((category + u'  ') + cmds)
    indent = (u' ' * (name_length + 2))
    msgs.append(u'\n'.join(textwrap.wrap(msg, subsequent_indent=indent)))
   url = create_gist(bot, u'\n\n'.join(msgs))
   if (not url):
    return
   bot.memory[u'command-gist'] = (len(bot.command_groups), url)
  bot.say(u"I've posted a list of my commands at {} - You can see more info about any of these commands by doing .help <command> (e.g. .help time)".format(url))

@ rule ( u'$nick(?i)(help|doc) +([A-Za-z]+)(?:\\?+)?$' ) @ example ( u'.help tell' ) @ commands ( u'help' , u'commands' ) @ priority ( u'low' ) def help ( bot , trigger ) : if trigger . group ( 2 ) : name = trigger . group ( 2 ) name = name . lower ( ) threshold = 3 if ( name in bot . doc ) : if ( ( len ( bot . doc [ name ] [ 0 ] ) + ( 1 if bot . doc [ name ] [ 1 ] else 0 ) ) > threshold ) : if ( trigger . nick != trigger . sender ) : bot . reply ( u"The documentation for this command is too long; I'm sending it to you in a private message." ) msgfun = ( lambda l : bot . msg ( trigger . nick , l ) ) else : msgfun = bot . reply for line in bot . doc [ name ] [ 0 ] : msgfun ( line ) if bot . doc [ name ] [ 1 ] : msgfun ( ( u'e.g. ' + bot . doc [ name ] [ 1 ] ) ) else : if ( ( u'command-gist' in bot . memory ) and ( bot . memory [ u'command-gist' ] [ 0 ] == len ( bot . command_groups ) ) ) : url = bot . memory [ u'command-gist' ] [ 1 ] else : bot . say ( u"Hang on, I'm creating a list." ) msgs = [ ] name_length = max ( 6 , max ( ( len ( k ) for k in bot . command_groups . keys ( ) ) ) ) for ( category , cmds ) in collections . OrderedDict ( sorted ( bot . command_groups . items ( ) ) ) . items ( ) : category = category . upper ( ) . ljust ( name_length ) cmds = u'  ' . join ( cmds ) msg = ( ( category + u'  ' ) + cmds ) indent = ( u' ' * ( name_length + 2 ) ) msgs . append ( u'\n' . join ( textwrap . wrap ( msg , subsequent_indent = indent ) ) ) url = create_gist ( bot , u'\n\n' . join ( msgs ) ) if ( not url ) : return bot . memory [ u'command-gist' ] = ( len ( bot . command_groups ) , url ) bot . say ( u"I've posted a list of my commands at {} - You can see more info about any of these commands by doing .help <command> (e.g. .help time)" . format ( url ) )
adds a charthelp object to the help attribute of the function .