Permalink
Browse files

Merge pull request #3 from vquaiato/patch-1

improving coderwall readability
  • Loading branch information...
2 parents d965a8b + 13c4c36 commit dcce1a712052db17f732045aa0e3e93c8981b229 @vquaiato vquaiato committed Jan 11, 2012
View
@@ -33,7 +33,8 @@
"shellwords": "0.0.x",
"nodepie": "0.4.0",
"mailer": "0.6.7",
- "scribe-node": "0.0.24"
+ "scribe-node": "0.0.24",
+ "sandbox": "0.8.2"
},
"directories": {
View
@@ -0,0 +1,89 @@
+# Allows Hubot to send text messages using 46elks.com API.
+#
+# you need to set HUBOT_46ELKS_USERNAME and HUBOT_46ELKS_PASSWORD
+#
+# sms <user> <message> - Sends <message> to the number <to>.
+# <user> has phone number <phone> - Sets the phone number of <user> to <phone>.
+# give me the phone number to <user> - Gets the phone number of <user>.e
+
+QS = require "querystring"
+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 /sms (\w+) (.*)/i, (msg) ->
+ to = msg.match[1]
+ bahdy = msg.match[2] # bahdy, that's how john mayer would say it.
+ user = process.env.HUBOT_46ELKS_USERNAME
+ pass = process.env.HUBOT_46ELKS_PASSWORD
+ from = "Hubot"
+ auth = 'Basic ' + new Buffer(user + ':' + pass).toString("base64")
+
+ unless user
+ msg.send "46Elks USERNAME isn't set."
+ msg.send "Please set the HUBOT_46ELKS_USERNAME environment variable."
+ return
+
+ unless pass
+ msg.send "46Elks PASSWORD isn't set."
+ msg.send "Please set the HUBOT_46ELKS_PASSWORD environment variable."
+ return
+
+ #get <user>'s phone number as listed in the brain
+ if user = robot.userForName(to)
+ if user.phone == ""
+ msg.send user.name + ' has no phone! set it with <user> has phone <phone>'
+ return
+ else
+ to = user.phone
+ to = to.toString().replace(/\d/, '+46')
+ else
+ msg.send 'Me cant find ' + to + ', are you sure that person is born?'
+ return
+
+ data = QS.stringify from: from, to: to, message: bahdy
+
+ msg.http("https://api.46elks.com")
+ .path("/a1/SMS")
+ .header("Authorization", auth)
+ .post(data) (err, res, body) ->
+ switch res.statusCode
+ when 200
+ msg.send "Sent sms to #{user.name}"
+ else
+ msg.send "Failed to send."
+
+ robot.respond /@?([\w .-_]+) has phone number (\d*)*$/i, (msg) ->
+ name = msg.match[1]
+ phone = msg.match[2].trim()
+
+
+ users = robot.usersForFuzzyName(name)
+ if users.length is 1
+ user = users[0]
+ if user.phone == phone
+ msg.send "I know."
+ else
+ user.phone = phone
+ msg.send "Ok, #{name} has phone #{phone}."
+ else if users.length > 1
+ msg.send getAmbiguousUserText users
+ else
+ msg.send "I don't know anything about #{name}."
+
+
+
+ robot.respond /@?give me the phone number to ([\w .-_]+)*/i, (msg) ->
+ name = msg.match[1]
+ users = robot.usersForFuzzyName(name)
+ if users.length is 1
+ user = users[0]
+ if user.phone.length < 1
+ msg.send "#{user.name} has no phone, set it first!"
+ else
+ msg.send "#{user.name} has phone number #{user.phone}."
+ else if users.length > 1
+ msg.send getAmbiguousUserText users
+ else
+ msg.send "I don't know anything about #{name}."
@@ -7,7 +7,7 @@
# developed by http://github.com/fellix - Crafters Software Studio
module.exports = (robot) ->
- robot.hear /^basecamp calendar( (.*))?$/i, (msg) ->
+ robot.hear /^basecamp calendar( (.*))?$/i, (msg) ->
project_name = msg.match[2]
basecamp_request msg, 'projects.json', (projects) ->
for project in projects.records
@@ -0,0 +1,10 @@
+#get last color from http://www.cheerlights.com
+module.exports = (robot) ->
+ robot.respond /cheerlights/i, (msg) ->
+ msg.http("http://api.thingspeak.com/channels/1417/field/1/last.json")
+ .get() (err, res, body) ->
+ response = JSON.parse body
+ if response
+ msg.send "The last color is: " + response["field1"]
+ else
+ msg.send "Error"
@@ -0,0 +1,28 @@
+# Chuck Norris awesomness.
+#
+#
+# chuck norris -- random Chuck Norris awesomeness.
+# chuck norris me <user> -- let's see how <user> would do as Chuck Norris.
+
+module.exports = (robot) ->
+
+ robot.respond /(chuck norris)( me )?(.*)/i, (msg)->
+ user = msg.match[3]
+ if user.length == 0
+ askChuck msg, "http://api.icndb.com/jokes/random"
+ else
+ askChuck msg, "http://api.icndb.com/jokes/random?firstName="+user+"&lastName="
+
+ askChuck = (msg, url) ->
+ msg.http(url)
+ .get() (err, res, body) ->
+ if err
+ msg.send "Chuck Norris says: #{err}"
+ else
+ message_from_chuck = JSON.parse(body)
+ if message_from_chuck.length == 0
+ msg.send "Achievement unlocked: Chuck Norris is quiet!"
+ else
+ msg.send message_from_chuck.value.joke
+
+
@@ -19,6 +19,6 @@ module.exports = (robot) ->
resp_str += user + "'s coderwall -> http://coderwall.com/"+user + "\n"
# Iterate all badges and continue building string
profile.badges.forEach (badge) ->
- resp_str += badge.name + " - " + badge.description + "\n"
+ resp_str += "[" + badge.name + "] - " + badge.description + "\n"
# Return response
msg.send resp_str
@@ -10,6 +10,7 @@ haters = [
, "http://i671.photobucket.com/albums/vv78/Sinsei55/HatersGonnaHatePanda.jpg"
, "http://24.media.tumblr.com/tumblr_lltwmdVpoL1qekprfo1_500.gif"
, "http://s3.amazonaws.com/kym-assets/photos/images/newsfeed/000/087/536/1292102239519.gif"
+, "http://i391.photobucket.com/albums/oo351/PikaPow3/squirtle.gif"
]
hatin = (msg) ->
View
@@ -0,0 +1,16 @@
+# insult <name> - give <name> the what-for
+
+module.exports = (robot) ->
+ robot.respond /insult (.*)/i, (msg) ->
+ name = msg.match[1].trim()
+ msg.send(insult(name))
+
+insult = (name) ->
+ insults[(Math.random() * insults.length) >> 0].replace(/{name}/, name);
+
+insults = [
+ "{name} is a scoundrel.",
+ "{name} should be ashamed of himself.",
+ "{name} is a motherless son of a goat.",
+ "{name} is a gravy-sucking pig."
+]
@@ -0,0 +1,10 @@
+# sandbox - run javascript in a sandbox!. Usage: /run <javascript> or /sandbox <javascript>
+
+Sandbox = require('Sandbox')
+
+module.exports = (robot) ->
+ robot.respond /(run|sandbox) (.*)/i, (msg) ->
+ sandbox = new Sandbox
+ sandbox.run(msg.match[2], (output) ->
+ msg.send output.result
+ )
View
@@ -1,41 +1,60 @@
-# Interact with your jenkins CI server, assumes you have a parameterized build
-# with the branch to build as a parameter
+# Interact with your Jenkins CI server
#
# You need to set the following variables:
# HUBOT_JENKINS_URL = "http://ci.example.com:8080"
-#
+#
# The following variables are optional
-# HUBOT_JENKINS_JOB: if not set you will have to specify job name every time
-# HUBOT_JENKINS_BRANCH_PARAMETER_NAME: if not set is assumed to be BRANCH_SPECIFIER
-# HUBOT_JENKINS_AUTH: for authenticating the trigger request (user:apiToken)
+# HUBOT_JENKINS_AUTH: for authenticating the trigger request (user:password)
+#
+# jenkins build <job> - builds the specified Jenkins job
+# jenkins build <job> with <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
+# jenkins list - lists Jenkins jobs
#
-# build branch master - starts a build for branch origin/master
-# build branch master on job Foo - starts a build for branch origin/master on job Foo
module.exports = (robot) ->
- robot.respond /build\s*(branch\s+)?([\w\/-]+)(\s+(on job)?\s*([\w-]+))?/i, (msg) ->
+ robot.respond /jenkins build ([\w\.\-_]+)( with (.+))?/i, (msg) ->
url = process.env.HUBOT_JENKINS_URL
+ job = msg.match[1]
+ params = msg.match[3]
- job = msg.match[5] || process.env.HUBOT_JENKINS_JOB
- job_parameter = process.env.HUBOT_JENKINS_BRANCH_PARAMETER_NAME || "BRANCH_SPECIFIER"
-
- branch = msg.match[2]
- branch = "origin/#{branch}" unless ~branch.indexOf("/")
-
- json_val = JSON.stringify parameter: [{name: job_parameter, value: branch}]
+ path = if params then "#{url}/job/#{job}/buildWithParameters?#{params}" else "#{url}/job/#{job}/build"
- req = msg.http("#{url}/job/#{job}/build/api/json")
+ req = msg.http(path)
if process.env.HUBOT_JENKINS_AUTH
auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
req.headers Authorization: "Basic #{auth}"
- req.headers 'Content-Type': 'application/x-www-form-urlencoded'
- req.post("json=#{json_val}") (err, res, body) ->
+ req.header('Content-Length', 0)
+ req.post() (err, res, body) ->
if err
msg.send "Jenkins says: #{err}"
else if res.statusCode == 302
- msg.send "Build started for #{branch}! #{res.headers.location}"
+ msg.send "Build started for #{job} #{res.headers.location}"
else
msg.send "Jenkins says: #{body}"
+
+ robot.respond /jenkins list/i, (msg) ->
+
+ url = process.env.HUBOT_JENKINS_URL
+ job = msg.match[1]
+ req = msg.http("#{url}/api/json")
+
+ if process.env.HUBOT_JENKINS_AUTH
+ auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
+ req.headers Authorization: "Basic #{auth}"
+
+ req.get() (err, res, body) ->
+ response = ""
+ if err
+ msg.send "Jenkins says: #{err}"
+ else
+ try
+ content = JSON.parse(body)
+ for job in content.jobs
+ state = if job.color == "red" then "FAIL" else "PASS"
+ response += "#{state} #{job.name}\n"
+ msg.send response
+ catch error
+ msg.send error
@@ -0,0 +1,5 @@
+# put back the table
+
+module.exports = (robot) ->
+ robot.hear /(╯°□°)╯︵ ┻━┻/i, (msg) ->
+ msg.send('┬──┬ ノ( ゜-゜ノ)')
View
@@ -0,0 +1,36 @@
+# reddit (me) <reddit> [limit] - Lookup reddit topic
+
+# Topic lookup from reddit
+# Enrique Vidal - enrique@cloverinteractive.com
+
+Select = require( "soupselect" ).select
+HTMLParser = require "htmlparser"
+
+lookup_site = "http://www.reddit.com/"
+
+module.exports = (robot)->
+ robot.respond /reddit( me)? ([a-z0-9\-_\.]+\/?[a-z0-9\-_\.]+)( [0-9]+)?/i, (message)->
+ lookup_reddit message, (text)->
+ message.send text
+
+ lookup_reddit = (message, response_handler)->
+ top = parseInt message.match[3]
+ reddit = "r/" + message.match[2] + ".json"
+
+ location = lookup_site + reddit
+
+ message.http( location ).get() (error, response, body)->
+ return response_handler "Sorry, something went wrong" if error
+ return response_handler "Reddit doesn't know what you're talking about" if response.statusCode == 404
+
+ list = JSON.parse( body ).data.children
+ count = 0
+
+ for item in list
+ count++
+
+ text = ( item.data.title || item.data.link_title ) + " - " + ( item.data.url || item.data.body )
+ response_handler text
+
+ break if count == top
+
Oops, something went wrong.

0 comments on commit dcce1a7

Please sign in to comment.