Skip to content
This repository has been archived by the owner on Jan 17, 2018. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'heroku/master'
Browse files Browse the repository at this point in the history
* heroku/master:
  OH THIS IS PERFECT.
  Changing a name.
  Initial commit

Conflicts:
	.gitignore
	README.md
	bin/hubot
	package.json
  • Loading branch information
bryanveloso committed Jan 28, 2012
2 parents 294bb87 + 473ac5d commit 930c1de
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
.DS_Store*
node_modules node_modules
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
app: bin/hubot -a campfire -n Tsunku
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -78,4 +78,3 @@ It's easy to test scripts locally with an interactive shell:
... and to run unit tests: ... and to run unit tests:


% make test % make test

9 changes: 9 additions & 0 deletions bin/hubot
@@ -1,3 +1,4 @@
<<<<<<< HEAD
#!/usr/bin/env coffee #!/usr/bin/env coffee
## ##
# hubot [options] # hubot [options]
Expand Down Expand Up @@ -101,4 +102,12 @@ else
robot.run() robot.run()


# vim:ft=coffee ts=2 sw=2 et : # vim:ft=coffee ts=2 sw=2 et :
=======
#!/bin/sh

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

exec node_modules/.bin/hubot "$@"
>>>>>>> heroku/master


1 change: 1 addition & 0 deletions hubot-scripts.json
@@ -0,0 +1 @@
["redis-brain.coffee", "tweet.coffee", "shipit.coffee"]
39 changes: 39 additions & 0 deletions scripts/google-images.coffee
@@ -0,0 +1,39 @@
# A way to interact with the Google Images API.
#
# image me <query> - The Original. Queries Google Images for <query> and
# returns a random top result.
# animate me <query> - The same thing as `image me`, except adds a few
# parameters to try to return an animated GIF instead.
# mustache me <url> - Adds a mustache to the specified URL.
# mustache me <query> - Searches Google Images for the specified query and
# mustaches it.
module.exports = (robot) ->
robot.respond /(image|img)( me)? (.*)/i, (msg) ->
imageMe msg, msg.match[3], (url) ->
msg.send url

robot.respond /animate me (.*)/i, (msg) ->
imageMe msg, "animated #{msg.match[1]}", (url) ->
msg.send url

robot.respond /(?:mo?u)?sta(?:s|c)he?(?: me)? (.*)/i, (msg) ->
type = Math.floor(Math.random() * 3)
mustachify = "http://mustachify.me/#{type}?src="
imagery = msg.match[1]

if imagery.match /^https?:\/\//i
msg.send "#{mustachify}#{imagery}"
else
imageMe msg, imagery, (url) ->
msg.send "#{mustachify}#{url}"

imageMe = (msg, query, cb) ->
msg.http('http://ajax.googleapis.com/ajax/services/search/images')
.query(v: "1.0", rsz: '8', q: query)
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData.results
if images.length > 0
image = msg.random images
cb "#{image.unescapedUrl}#.png"

14 changes: 14 additions & 0 deletions scripts/help.coffee
@@ -0,0 +1,14 @@
# Generates help commands for Hubot.
#
# These commands are grabbed from comment blocks at the top of each file.
#
# help - Displays all of the help commands that Hubot knows about.
# help <query> - Displays all help commands that match <query>.

module.exports = (robot) ->
robot.respond /help\s*(.*)?$/i, (msg) ->
cmds = robot.helpCommands()
if msg.match[1]
cmds = cmds.filter (cmd) -> cmd.match(new RegExp(msg.match[1]))
msg.send cmds.join("\n")

24 changes: 24 additions & 0 deletions scripts/maps.coffee
@@ -0,0 +1,24 @@
# Interacts with the Google Maps API.
#
# map me <query> - Returns a map view of the area returned by `query`.

module.exports = (robot) ->

robot.respond /(?:(satellite|terrain|hybrid)[- ])?map me (.+)/i, (msg) ->
mapType = msg.match[1] or "roadmap"
location = msg.match[2]
mapUrl = "http://maps.google.com/maps/api/staticmap?markers=" +
escape(location) +
"&size=400x400&maptype=" +
mapType +
"&sensor=false" +
"&format=png" # So campfire knows it's an image
url = "http://maps.google.com/maps?q=" +
escape(location) +
"&hl=en&sll=37.0625,-95.677068&sspn=73.579623,100.371094&vpsrc=0&hnear=" +
escape(location) +
"&t=m&z=11"

msg.send mapUrl
msg.send url

20 changes: 20 additions & 0 deletions scripts/math.coffee
@@ -0,0 +1,20 @@
# 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.'

15 changes: 15 additions & 0 deletions scripts/ping.coffee
@@ -0,0 +1,15 @@
# Utility commands surrounding Hubot uptime.
module.exports = (robot) ->
robot.respond /PING$/i, (msg) ->
msg.send "PONG"

robot.respond /ECHO (.*)$/i, (msg) ->
msg.send msg.match[1]

robot.respond /TIME$/i, (msg) ->
msg.send "Server time is: #{new Date()}"

robot.respond /DIE$/i, (msg) ->
msg.send "Goodbye, cruel world."
process.exit 0

23 changes: 23 additions & 0 deletions scripts/pugme.coffee
@@ -0,0 +1,23 @@
# Pugme is the most important thing in your life
#
# pug me - Receive a pug
# pug bomb N - get N pugs

module.exports = (robot) ->

robot.respond /pug me/i, (msg) ->
msg.http("http://pugme.herokuapp.com/random")
.get() (err, res, body) ->
msg.send JSON.parse(body).pug

robot.respond /pug bomb( (\d+))?/i, (msg) ->
count = msg.match[2] || 5
msg.http("http://pugme.herokuapp.com/bomb?count=" + count)
.get() (err, res, body) ->
msg.send pug for pug in JSON.parse(body).pugs

robot.respond /how many pugs are there/i, (msg) ->
msg.http("http://pugme.herokuapp.com/count")
.get() (err, res, body) ->
msg.send "There are #{JSON.parse(body).pug_count} pugs."

80 changes: 80 additions & 0 deletions scripts/roles.coffee
@@ -0,0 +1,80 @@
# Assign roles to people you're chatting with
#
# <user> is a badass guitarist - assign a role to a user
# <user> is not a badass guitarist - remove a role from a user
# who is <user> - see what roles a user has

# hubot holman is an ego surfer
# hubot holman is not an ego surfer
#

module.exports = (robot) ->

getAmbiguousUserText = (users) ->
"Be more specific, I know #{users.length} people named like that: #{(user.name for user in users).join(", ")}"

robot.respond /who is @?([\w .-]+)\?*$/i, (msg) ->
name = msg.match[1]

if name is "you"
msg.send "Who ain't I?"
else if name is robot.name
msg.send "The best."
else
users = robot.usersForFuzzyName(name)
if users.length is 1
user = users[0]
user.roles = user.roles or [ ]
if user.roles.length > 0
msg.send "#{name} is #{user.roles.join(", ")}."
else
msg.send "#{name} is nothing to me."
else if users.length > 1
msg.send getAmbiguousUserText users
else
msg.send "#{name}? Never heard of 'em"

robot.respond /@?([\w .-_]+) is (["'\w: -_]+)[.!]*$/i, (msg) ->
name = msg.match[1]
newRole = msg.match[2].trim()

unless name in ['who', 'what', 'where', 'when', 'why']
unless newRole.match(/^not\s+/i)
users = robot.usersForFuzzyName(name)
if users.length is 1
user = users[0]
user.roles = user.roles or [ ]

if newRole in user.roles
msg.send "I know"
else
user.roles.push(newRole)
if name.toLowerCase() is robot.name
msg.send "Ok, I am #{newRole}."
else
msg.send "Ok, #{name} is #{newRole}."
else if users.length > 1
msg.send getAmbiguousUserText users
else
msg.send "I don't know anything about #{name}."

robot.respond /@?([\w .-_]+) is not (["'\w: -_]+)[.!]*$/i, (msg) ->
name = msg.match[1]
newRole = msg.match[2].trim()

unless name in ['who', 'what', 'where', 'when', 'why']
users = robot.usersForFuzzyName(name)
if users.length is 1
user = users[0]
user.roles = user.roles or [ ]

if newRole not in user.roles
msg.send "I know."
else
user.roles = (role for role in user.roles when role isnt newRole)
msg.send "Ok, #{name} is no longer #{newRole}."
else if users.length > 1
msg.send getAmbiguousUserText users
else
msg.send "I don't know anything about #{name}."

25 changes: 25 additions & 0 deletions scripts/rules.coffee
@@ -0,0 +1,25 @@
# DON'T DELETE THIS SCRIPT! ALL ROBAWTS MUST KNOW THE RULES

rules = [
"1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.",
"2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.",
"3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law."
]

otherRules = [
"A developer may not injure Apple or, through inaction, allow Apple to come to harm.",
"A developer must obey any orders given to it by Apple, except where such orders would conflict with the First Law.",
"A developer must protect its own existence as long as such protection does not conflict with the First or Second Law."
]

# Make sure that hubot knows the rules.
#
# the rules - Make sure hubot still knows the rules.
module.exports = (robot) ->
robot.respond /(what are )?the (three |3 )?(rules|laws)/i, (msg) ->
text = msg.message.text
if text.match(/apple/i) or text.match(/dev/i)
msg.send otherRules.join('\n')
else
msg.send rules.join('\n')

23 changes: 23 additions & 0 deletions scripts/storage.coffee
@@ -0,0 +1,23 @@
# Inspect the data in redis easily
#
# show users - Display all users that hubot knows about
# show storage - Display the contents that are persisted in redis
#

Util = require "util"

module.exports = (robot) ->
robot.respond /show storage$/i, (msg) ->
output = Util.inspect(robot.brain.data, false, 4)
msg.send output

robot.respond /show users$/i, (msg) ->
response = ""

for own key, user of robot.brain.data.users
response += "#{user.id} #{user.name}"
response += " <#{user.email_address}>" if user.email_address
response += "\n"

msg.send response

97 changes: 97 additions & 0 deletions scripts/translate.coffee
@@ -0,0 +1,97 @@
# Allows Hubot to know many languages.
#
# translate me <phrase> - Searches for a translation for the <phrase> and then
# prints that bad boy out.
#
# translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
#

languages =
"af": "Afrikaans",
"sq": "Albanian",
"ar": "Arabic",
"be": "Belarusian",
"bg": "Bulgarian",
"ca": "Catalan",
"zh-CN": "Simplified Chinese",
"zh-TW": "Traditional Chinese",
"hr": "Croatian",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"en": "English",
"et": "Estonian",
"tl": "Filipino",
"fi": "Finnish",
"fr": "French",
"gl": "Galician",
"de": "German",
"el": "Greek",
"iw": "Hebrew",
"hi": "Hindi",
"hu": "Hungarian",
"is": "Icelandic",
"id": "Indonesian",
"ga": "Irish",
"it": "Italian",
"ja": "Japanese",
"ko": "Korean",
"lv": "Latvian",
"lt": "Lithuanian",
"mk": "Macedonian",
"ms": "Malay",
"mt": "Maltese",
"no": "Norwegian",
"fa": "Persian",
"pl": "Polish",
"pt": "Portuguese",
"ro": "Romanian",
"ru": "Russian",
"sr": "Serbian",
"sk": "Slovak",
"sl": "Slovenian",
"es": "Spanish",
"sw": "Swahili",
"sv": "Swedish",
"th": "Thai",
"tr": "Turkish",
"uk": "Ukranian",
"vi": "Vietnamese",
"cy": "Welsh",
"yi": "Yiddish"

getCode = (language,languages) ->
for code, lang of languages
return code if lang.toLowerCase() is language.toLowerCase()

module.exports = (robot) ->
robot.respond /(?:translate)(?: me)?(?:(?: from) ([a-z]*))?(?:(?: (?:in)?to) ([a-z]*))? (.*)/i, (msg) ->
term = "\"#{msg.match[3]}\""
origin = if msg.match[1] isnt undefined then getCode(msg.match[1], languages) else 'auto'
target = if msg.match[2] isnt undefined then getCode(msg.match[2], languages) else 'en'

msg.http("http://translate.google.com/translate_a/t")
.query({
client: 't'
hl: 'en'
multires: 1
sc: 1
sl: origin
ssel: 0
tl: target
tsel: 0
uptl: "en"
text: term
})
.get() (err, res, body) ->
data = body
if data.length > 4 && data[0] == '['
parsed = eval(data)
language =languages[parsed[2]]
parsed = parsed[0] && parsed[0][0] && parsed[0][0][0]
if parsed
if msg.match[2] is undefined
msg.send "#{term} is #{language} for #{parsed}"
else
msg.send "The #{language} #{term} translates as #{parsed} in #{languages[target]}"

0 comments on commit 930c1de

Please sign in to comment.