Skip to content

Commit

Permalink
v4 Syntax+ bug fix
Browse files Browse the repository at this point in the history
Changed to v4 Syntax
Fixed conflict with same callable name
Fixed using input.group instead of trigger.group in help command (5 months since last commit and no one noticed that .help doesn't work?)
  • Loading branch information
303i committed Jun 4, 2013
1 parent 688f20d commit b953255
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,50 @@
http://willie.dftba.net
"""
from willie.module import command, rule, example, priority

def doc(willie, trigger):
@rule('$nick' '(?i)(help|doc) +([A-Za-z]+)(?:\?+)?$')
@example('$nickname: help tell')
@priority('low')
def doc(bot, trigger):
"""Shows a command's documentation, and possibly an example."""
name = trigger.group(2)
name = name.lower()

if willie.doc.has_key(name):
willie.reply(willie.doc[name][0])
if willie.doc[name][1]:
willie.say('e.g. ' + willie.doc[name][1])
doc.rule = ('$nick', '(?i)(help|doc) +([A-Za-z]+)(?:\?+)?$')
doc.example = '$nickname: doc tell?'
doc.priority = 'low'

def help(willie, trigger):
if bot.doc.has_key(name):
bot.reply(bot.doc[name][0])
if bot.doc[name][1]:
bot.say('e.g. ' + bot.doc[name][1])

@command('help')
@example('.help c')
def help(bot, trigger):
"""Get help for a command."""
if not input.group(2):
willie.reply('Say .help <command> (for example .help c) to get help for a command, or .commands for a list of commands.')
if not trigger.group(2):
bot.reply('Say .help <command> (for example .help c) to get help for a command, or .commands for a list of commands.')
else:
doc(willie, trigger)
help.commands = ['help']
help.example = '.help c'
doc(bot, trigger)

def commands(willie, trigger):
"""Return a list of Willie's commands"""
names = ', '.join(sorted(willie.doc.iterkeys()))
willie.reply("I am sending you a private message of all my commands!")
willie.msg(trigger.nick, 'Commands I recognise: ' + names + '.')
willie.msg(trigger.nick, ("For help, do '%s: help example?' where example is the " +
"name of the command you want help for.") % willie.nick)
commands.commands = ['commands']
commands.priority = 'low'
@command('commands')
@priority('low')
def commands(bot, trigger):
"""Return a list of bot's commands"""
names = ', '.join(sorted(bot.doc.iterkeys()))
bot.reply("I am sending you a private message of all my commands!")
bot.msg(trigger.nick, 'Commands I recognise: ' + names + '.')
bot.msg(trigger.nick, ("For help, do '%s: help example' where example is the " +
"name of the command you want help for.") % bot.nick)

def help(willie, trigger):
@rule('$nick' r'(?i)help(?:[?!]+)?$')
@priority('low')
def help2(bot, trigger):
response = (
'Hi, I\'m a bot. Say ".commands" to me in private for a list ' +
'of my commands, or see http://willie.dftba.net for more ' +
'general details. My owner is %s.'
) % willie.config.owner
willie.reply(response)
help.rule = ('$nick', r'(?i)help(?:[?!]+)?$')
help.priority = 'low'
) % bot.config.owner
bot.reply(response)


if __name__ == '__main__':
print __doc__.strip()

0 comments on commit b953255

Please sign in to comment.