Skip to content

Commit

Permalink
[announce github help lmgtfy search units] PEP8 per sopel-irc#125
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Jun 22, 2013
1 parent d3a8021 commit b5e9070
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from willie.module import command, example


@command('announce')
@example('.announce Some important message here')
def announce(bot, trigger):
Expand Down
1 change: 1 addition & 0 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from willie import web
from willie.module import commands


def checkConfig(bot):
if not bot.config.has_option('github', 'oauth_token') or not bot.config.has_option('github', 'repo'):
return False
Expand Down
5 changes: 4 additions & 1 deletion help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
from willie.module import command, rule, example, priority


@rule('$nick' '(?i)(help|doc) +([A-Za-z]+)(?:\?+)?$')
@example('.help tell')
@command('help')
Expand All @@ -20,11 +21,12 @@ def help(bot, trigger):
name = trigger.group(2)
name = name.lower()

if bot.doc.has_key(name):
if name in bot.doc:
bot.reply(bot.doc[name][0])
if bot.doc[name][1]:
bot.say('e.g. ' + bot.doc[name][1])


@command('commands')
@priority('low')
def commands(bot, trigger):
Expand All @@ -35,6 +37,7 @@ def commands(bot, trigger):
bot.msg(trigger.nick, ("For help, do '%s: help example' where example is the " +
"name of the command you want help for.") % bot.nick)


@rule('$nick' r'(?i)help(?:[?!]+)?$')
@priority('low')
def help2(bot, trigger):
Expand Down
1 change: 1 addition & 0 deletions lmgtfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from willie.module import commands


@commands('lmgtfy', 'lmgify', 'gify', 'gtfy')
def googleit(bot, trigger):
"""Let me just... google that for you."""
Expand Down
1 change: 1 addition & 0 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def bing_search(query, lang='en-GB'):

r_duck = re.compile(r'nofollow" class="[^"]+" href="(.*?)">')


def duck_search(query):
query = query.replace('!', '')
query = web.quote(query)
Expand Down
21 changes: 12 additions & 9 deletions units.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
from willie.module import command, commands, example, NOLIMIT
import re

find_temp = re.compile('(-?[0-9]*\.?[0-9]*)[ °]*(K|C|F)', re.IGNORECASE)
find_length = re.compile('([0-9]*\.?[0-9]*)[ ]*(mile[s]?|mi|inch|in|foot|feet|ft|yard[s]?|yd|(?:centi|kilo|)meter[s]?|[kc]?m)', re.IGNORECASE)
find_temp = re.compile('(-?[0-9]*\.?[0-9]*)[ °]*(K|C|F)', re.IGNORECASE)
find_length = re.compile('([0-9]*\.?[0-9]*)[ ]*(mile[s]?|mi|inch|in|foot|feet|ft|yard[s]?|yd|(?:centi|kilo|)meter[s]?|[kc]?m)', re.IGNORECASE)


def f_to_c(temp):
return (float(temp) - 32) * 5/9
return (float(temp) - 32) * 5 / 9


def c_to_k(temp):
return temp + 273.15


def c_to_f(temp):
return (9.0/5.0 * temp + 32)
return (9.0 / 5.0 * temp + 32)


def k_to_c(temp):
return temp - 273.15
Expand Down Expand Up @@ -50,6 +54,7 @@ def temperature(bot, trigger):
fahrenheit = c_to_f(celsius)
bot.reply("%s°C = %s°F = %sK" % (celsius, fahrenheit, kelvin))


@commands('length', 'distance')
@example('.distance 3km')
def distance(bot, trigger):
Expand All @@ -64,17 +69,17 @@ def distance(bot, trigger):
unit = source[1].lower()
numeric = float(source[0])
meter = 0
if unit in ("meters","meter", "m"):
if unit in ("meters", "meter", "m"):
meter = numeric
elif unit in ("kilometers", "kilometer", "km"):
meter = numeric * 1000
elif unit in ("miles", "mile", "mi"):
meter = numeric / 0.00062137
elif unit in ("inch", "in"):
meter = numeric / 39.370
elif unit in ("centimeters","centimeter","cm"):
elif unit in ("centimeters", "centimeter", "cm"):
meter = numeric / 100
elif unit in ("feet","foot","ft"):
elif unit in ("feet", "foot", "ft"):
meter = numeric / 3.2808
elif unit in ("yards", "yard", "yd"):
meter = numeric / (3.2808 * 3)
Expand All @@ -86,7 +91,6 @@ def distance(bot, trigger):
else:
metric_part = '%sm' % meter


# Shit like this makes me hate being an American.
inch = meter * 39.37
foot = int(inch) / 12
Expand Down Expand Up @@ -118,4 +122,3 @@ def distance(bot, trigger):
stupid_part = ', '.join(parts)

bot.reply('%s = %s' % (metric_part, stupid_part))

0 comments on commit b5e9070

Please sign in to comment.