Skip to content

Instantly share code, notes, and snippets.

@pattonjp
Created February 20, 2014 00:14
Show Gist options
  • Save pattonjp/9104365 to your computer and use it in GitHub Desktop.
Save pattonjp/9104365 to your computer and use it in GitHub Desktop.
drunkbot... a partying hubot
# Description:
# It's Miller Time!!!.
#
# Commands:
# hubot beer me <query> - Queries Google Images for beer <query> and returns a random top result.
uDrinkin = [
"I'll buy",
"Yep!",
"i'll have a double",
"You buying?"
]
module.exports = (robot) ->
robot.respond /(beer)( me)? (.*)/i, (msg) ->
qry = "beer #{msg.match[3]}"
console.log qry
imageMe msg, qry, (url) ->
msg.send url
robot.respond /(cocktail)( me)? (.*)/i, (msg) ->
qry = "cocktail #{msg.match[3]}"
console.log qry
imageMe msg, qry, (url) ->
msg.send url
robot.respond /(shots)(.*)/i, (msg) ->
msg.send msg.random uDrinkin
robot.hear /(^|\s)hh/i, (msg) ->
msg.send msg.random uDrinkin
imageMe = (msg, query, animated, faces, cb) ->
cb = animated if typeof animated == 'function'
cb = faces if typeof faces == 'function'
q = v: '1.0', rsz: '8', q: query, safe: 'active'
q.as_filetype = 'gif' if typeof animated is 'boolean' and animated is true
q.imgtype = 'face' if typeof faces is 'boolean' and faces is true
msg.http('http://ajax.googleapis.com/ajax/services/search/images')
.query(q)
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData.results
if images.length > 0
image = msg.random images
cb "#{image.unescapedUrl}#.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment