Skip to content

Commit

Permalink
[reload, search] Finally finish updating to 4.0 syntax.
Browse files Browse the repository at this point in the history
Fixes #276
  • Loading branch information
embolalia committed Jun 24, 2013
1 parent 9ea4f27 commit f290319
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion willie/modules/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def f_reload(bot, trigger):


if sys.version_info >= (2, 7):
@willie.module.nickname_commands('update')
def update(bot, trigger):
if not trigger.admin:
return
Expand All @@ -83,9 +84,9 @@ def update(bot, trigger):

f_reload(bot, trigger)
else:
@willie.module.nickname_commands('update')
def update(bot, trigger):
bot.say('You need to run me on Python 2.7 to do that.')
update.rule = ('$nick', ['update'], r'(.+)')


@willie.module.nickname_commands("load")
Expand Down
29 changes: 13 additions & 16 deletions willie/modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"""

import re
import willie.web as web
from willie import web
from willie.module import commands, example
import json
import time

Expand Down Expand Up @@ -50,6 +51,8 @@ def formatnumber(n):
return ''.join(parts)


@commands('g', 'google')
@example('.g swhack')
def g(bot, trigger):
"""Queries Google for the specified input."""
query = trigger.group(2)
Expand All @@ -63,27 +66,25 @@ def g(bot, trigger):
bot.reply("Problem getting data from Google.")
else:
bot.reply("No results found for '%s'." % query)
g.commands = ['g', 'google']
g.priority = 'high'
g.example = '.g swhack'


@commands('gc')
@example('.gc extrapolate')
def gc(bot, trigger):
"""Returns the number of Google results for the specified input."""
query = trigger.group(2)
if not query:
return bot.reply('.gc what?')
num = formatnumber(google_count(query))
bot.say(query + ': ' + num)
gc.commands = ['gc']
gc.priority = 'high'
gc.example = '.gc extrapolate'

r_query = re.compile(
r'\+?"[^"\\]*(?:\\.[^"\\]*)*"|\[[^]\\]*(?:\\.[^]\\]*)*\]|\S+'
)


@commands('gcs', 'comp')
@example('.gcs foo bar')
def gcs(bot, trigger):
"""Compare the number of Google search results"""
if not trigger.group(2):
Expand All @@ -105,8 +106,6 @@ def gcs(bot, trigger):
results = [(term, n) for (n, term) in reversed(sorted(results))]
reply = ', '.join('%s (%s)' % (t, formatnumber(n)) for (t, n) in results)
bot.say(reply)
gcs.commands = ['gcs', 'comp']
gcs.example = '.gcs foo bar'

r_bing = re.compile(r'<h3><a href="([^"]+)"')

Expand Down Expand Up @@ -146,6 +145,8 @@ def duck_api(query):
return None


@commands('duck', 'ddg')
@example('.duck privacy or .duck !mcwiki obsidian')
def duck(bot, trigger):
"""Queries Duck Duck Go for the specified input."""
query = trigger.group(2)
Expand All @@ -166,9 +167,10 @@ def duck(bot, trigger):
bot.memory['last_seen_url'][trigger.sender] = uri
else:
bot.reply("No results found for '%s'." % query)
duck.commands = ['duck', 'ddg']


@commands('search')
@example('.search nerdfighter')
def search(bot, trigger):
"""Searches Google, Bing, and Duck Duck Go."""
if not trigger.group(2):
Expand Down Expand Up @@ -196,10 +198,9 @@ def search(bot, trigger):
result = '%s (g), %s (b), %s (d)' % (gu, bu, du)

bot.reply(result)
search.commands = ['search']
search.example = '.search nerdfighter'


@commands('suggest')
def suggest(bot, trigger):
"""Suggest terms starting with given input"""
if not trigger.group(2):
Expand All @@ -211,7 +212,3 @@ def suggest(bot, trigger):
bot.say(answer)
else:
bot.reply('Sorry, no result.')
suggest.commands = ['suggest']

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

0 comments on commit f290319

Please sign in to comment.