Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: e9124bf56a
Fetching contributors…

Cannot retrieve contributors at this time

21 lines (19 sloc) 0.763 kb
# Allows Hubot to do mathematics.
#
# math me <expression> - Calculate the given expression.
# convert me <expression> to <units> - Convert expression to given units.
module.exports = (robot) ->
robot.respond /(calc|calculate|convert|math)( me)? (.*)/i, (msg) ->
msg
.http('http://www.google.com/ig/calculator')
.query
hl: 'en'
q: msg.match[3]
.headers
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Charset': 'utf-8',
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
.get() (err, res, body) ->
# Response includes non-string keys, so we can't use JSON.parse here.
json = eval("(#{body})")
msg.send json.rhs || 'Could not compute.'
Jump to Line
Something went wrong with that request. Please try again.