From b953255364b54e1abef7a1e44f7d3365777567ed Mon Sep 17 00:00:00 2001 From: 303i Date: Tue, 4 Jun 2013 18:15:22 +0800 Subject: [PATCH] v4 Syntax+ bug fix 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?) --- info.py | 60 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/info.py b/info.py index 071e3956d9..b0bbb8b2f0 100644 --- a/info.py +++ b/info.py @@ -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 (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 (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()