Skip to content

Commit

Permalink
Merge pull request github#3 from sleekslush/master
Browse files Browse the repository at this point in the history
Adds the Corbis script plus a few other ones from the github upstream remote
  • Loading branch information
Zakaria Zajac committed Nov 13, 2011
2 parents 12c9eab + 0ff8093 commit 4af4ac4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/scripts/corbis.coffee
@@ -0,0 +1,15 @@
# Returns the full URL for the Corbis id provided.
#
# corbis (image) me <corbis_id>

module.exports = (robot) ->
robot.respond /corbis(?: image)? me (.+)/i, (msg) ->
corbis_id = msg.match[1]

msg
.http("http://www.corbisimages.com/stock-photo/#{corbis_id}")
.get() (err, res, body) ->
if res.statusCode is 301
msg.send "http://www.corbisimages.com#{res.headers.location}"
else
msg.send "Not found"
42 changes: 42 additions & 0 deletions src/scripts/dialectizer.coffee
@@ -0,0 +1,42 @@
Select = require("soupselect").select
HtmlParser = require "htmlparser"

#TODO: get this dynamically?
dialects = ["redneck", "jive", "cockney", "fudd", "bork", "moron", "piglatin", "hckr", "censor"]

module.exports = (robot) ->
robot.respond /(?:dialectize|dialect|dia) (\w+)(.*)/i, (msg) ->
[dialect, text] = msg.match[1..2]
if dialect in ["help", "h"]
showHelp(msg)
return

return unless text
trim text
return unless text.length > 0

if dialect in ["all", "a"]
showDialectizedText(msg, dialect, text, true) for dialect in dialects
return
else if dialect is "hacker"
dialect = "hckr"
showDialectizedText(msg, dialect, text, false)

showDialectizedText = (msg, dialect, text, showPrefix) ->
msg.http("http://www.rinkworks.com/dialect/dialectt.cgi?dialect=" + encodeURIComponent(dialect) + "&text=" + encodeURIComponent(text))
.get() (err, res, body) ->
handler = new HtmlParser.DefaultHandler()
parser = new HtmlParser.Parser handler
parser.parseComplete body
result = Select handler.dom, ".dialectized_text p"
return unless result
dialectizedText = trim result[0].children[0].raw
dialectizedText = "#{dialect}: " + dialectizedText if showPrefix
msg.send dialectizedText

showHelp = (msg) ->
msg.send "Dialects: " + dialects.join(", ")

trim = (string) ->
return string.replace(/^\s*|\s*$/g, '')

24 changes: 24 additions & 0 deletions src/scripts/kittens.coffee
@@ -0,0 +1,24 @@

# Kittens!
#
# kitten me - A randomly selected kitten
# kitten me <w>x<h> - A kitten of the given size
# kitten bomb me <number> - Many many kittens!

module.exports = (robot) ->
robot.respond /kittens?(?: me)?$/i, (msg) ->
msg.send kittenMe()

robot.respond /kittens?(?: me)? (\d+)(?:[x ](\d+))?$/i, (msg) ->
msg.send kittenMe msg.match[1], (msg.match[2] || msg.match[1])

robot.respond /kitten bomb(?: me)?( \d+)?$/i, (msg) ->
kittens = msg.match[1] || 5
msg.send(kittenMe()) for i in [1..kittens]

kittenMe = (height, width)->
h = height || Math.floor(Math.random()*250) + 250
w = width || Math.floor(Math.random()*250) + 250
root = "http://placekitten.com"
root += "/g" if Math.random() > 0.5 # greyscale kittens!
return "#{root}/#{h}/#{w}#.png"
16 changes: 16 additions & 0 deletions src/scripts/walmart.coffee
@@ -0,0 +1,16 @@
# Show a random image from peopleofwalmart.com
#
# walmart me - Show random Walmart image
# mart me - Show random Walmart image
#
module.exports = (robot) ->
robot.respond /(wal)?mart( me)?/i, (msg) ->
random = Math.floor(Math.random() * 770)
msg.http("http://www.peopleofwalmart.com/photos/random-photos/page/" + random)
.get() (err, res, body) ->
col1 = body.indexOf '<div class="column_one">'
if (col1 != -1)
body = body.substring col1
match = body.match /http:\/\/media.peopleofwalmart.com\/wp-content\/uploads\/\d\d\d\d\/\d\d\/.+?\.jpg/g
if (match)
msg.send match[0]

0 comments on commit 4af4ac4

Please sign in to comment.