forked from github/hubot-scripts
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#3 from sleekslush/master
Adds the Corbis script plus a few other ones from the github upstream remote
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, '') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |