From 35473fffa3b62e7451633c7221a303469f181d56 Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Fri, 31 May 2013 16:54:48 -0400 Subject: [PATCH] [wikipedia] Bring module to 4.0 standards per issue #276 --- willie/modules/wikipedia.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/willie/modules/wikipedia.py b/willie/modules/wikipedia.py index efa71c2212..cbc64bf22f 100644 --- a/willie/modules/wikipedia.py +++ b/willie/modules/wikipedia.py @@ -5,12 +5,14 @@ http://willie.dftba.net """ -import willie.web as web +from willie import web +from willie.module import NOLIMIT, commands, example import json import re REDIRECT = re.compile(r'^REDIRECT (.*)') + def mw_search(server, query, num): """ Searches the specified MediaWiki server for the given query, and returns @@ -44,21 +46,21 @@ def mw_snippet(server, query): return snippet['extract'] -def wikipedia(willie, trigger): +@commands('w', 'wiki', 'wik') +@example('.w San Francisco') +def wikipedia(bot, trigger): query = trigger.group(2) if not query: - willie.reply('What do you want me to look up?') - return willie.NOLIMIT + bot.reply('What do you want me to look up?') + return NOLIMIT server = 'en.wikipedia.org' query = mw_search(server, query, 1) if not query: - willie.reply("I can't find any results for that.") - return willie.NOLIMIT + bot.reply("I can't find any results for that.") + return NOLIMIT else: query = query[0] snippet = mw_snippet(server, query) query = query.replace(' ', '_') - willie.say('"%s" - http://en.wikipedia.org/wiki/%s' % (snippet, query)) -wikipedia.commands = ['w', 'wiki', 'wik'] -wikipedia.example = '.w San Francisco' + bot.say('"%s" - http://en.wikipedia.org/wiki/%s' % (snippet, query))