Permalink
Browse files

Merge branch 'master' of github.com:github/hubot-scripts

  • Loading branch information...
2 parents 274c8cc + bb2af93 commit a8a4f58048f6d23356780b267d11ae631df792c1 @tombell tombell committed Jan 18, 2013
@@ -55,7 +55,7 @@ module.exports = (robot) ->
get_languages robot, (languages) ->
lang_msg = 'Known Languages\n\n'
for own id, desc of languages
- lang_msg += "#{id}: #{desc}"
+ lang_msg += "#{id}: #{desc}\n"
msg.send lang_msg
robot.respond /eval[,:]? +on +([a-z]+) *$/i, (msg) ->
@@ -0,0 +1,33 @@
+# Description:
+# Hubot, be polite and say hello.
+#
+# Dependencies:
+# None
+#
+# Configuration:
+# None
+#
+# Commands:
+# Hello or Good Day make hubot say hello to you back
+# Good Morning makes hubot say good morning to you back
+hellos = [
+ "Well hello there, %",
+ "Hey %, Hello!",
+ "Marnin', %",
+ "Good day, %",
+ "Good 'aye!, %"
+]
+mornings = [
+ "Good morning, %",
+ "Good morning to you too, %",
+ "Good day, %",
+ "Good 'aye!, %"
+]
+module.exports = (robot) ->
+ robot.hear /(hello|good( [d'])?ay(e)?)/i, (msg) ->
+ hello = msg.random hellos
+ msg.send hello.replace "%", msg.message.user.name
+
+ robot.hear /(^(good )?m(a|o)rnin(g)?)/i, (msg) ->
+ hello = msg.random mornings
+ msg.send hello.replace "%", msg.message.user.name
Oops, something went wrong.
@@ -11,7 +11,7 @@
# Commands:
# hubot jenkins build <job> - builds the specified Jenkins job
# hubot jenkins build <job>, <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
-# hubot jenkins list - lists Jenkins jobs
+# hubot jenkins list <filter> - lists Jenkins jobs
# hubot jenkins describe <job> - Describes the specified Jenkins job
#
@@ -95,7 +95,7 @@ jenkinsDescribe = (msg) ->
jenkinsList = (msg) ->
url = process.env.HUBOT_JENKINS_URL
- job = msg.match[1]
+ filter = new RegExp(msg.match[2], 'i')
req = msg.http("#{url}/api/json")
if process.env.HUBOT_JENKINS_AUTH
@@ -111,7 +111,8 @@ jenkinsList = (msg) ->
content = JSON.parse(body)
for job in content.jobs
state = if job.color == "red" then "FAIL" else "PASS"
- response += "#{state} #{job.name}\n"
+ if filter.test job.name
+ response += "#{state} #{job.name}\n"
msg.send response
catch error
msg.send error
@@ -120,7 +121,7 @@ module.exports = (robot) ->
robot.respond /jenkins build ([\w\.\-_ ]+)(, (.+))?/i, (msg) ->
jenkinsBuild(msg)
- robot.respond /jenkins list/i, (msg) ->
+ robot.respond /jenkins list( (.+))?/i, (msg) ->
jenkinsList(msg)
robot.respond /jenkins describe (.*)/i, (msg) ->
@@ -31,7 +31,10 @@ class IssueFilters
@cache = []
@robot.brain.on 'loaded', =>
- @cache = @robot.brain.data.jqls
+ jqls_from_brain = @robot.brain.data.jqls
+ # only overwrite the cache from redis if data exists in redis
+ if jqls_from_brain
+ @cache = jqls_from_brain
add: (filter) ->
@cache.push filter
@@ -42,7 +42,8 @@ module.exports = (robot) ->
"#{robot.name} 3d unlock - unlocks the printer after you clean up\n\n" +
"Only 1 print at a time is allowed, and you are required to tell\n" +
"#{robot.name} after you've cleaned your print off.\n\n" +
- "The most current log is always available at #{makeServer}/log"
+ "The web frontend is at #{makeServer}, and\n" +
+ "the most current log is always available at #{makeServer}/log\n\n" +
msg.send response
robot.respond /3d (snapshot|status)/i, (msg) ->
@@ -123,10 +124,10 @@ module.exports = (robot) ->
}
})) (err, res, body) =>
if res.statusCode is 200
- msg.reply "Your thing is printin'! Check logs at #{makeServer}/log"
+ msg.reply "Your thing is printin'! Check logs at #{makeServer}"
else if res.statusCode is 409
msg.reply "I couldn't process that pile of triangles."
else if res.statusCode is 423
- msg.reply "Wait your turn, someone is already printing a thing. You can check progress at #{makeServer}/log"
+ msg.reply "Wait your turn, someone is already printing a thing. You can check progress at #{makeServer}"
else if err or res.statusCode is 500
msg.reply "Something broke!"
@@ -26,6 +26,7 @@
# hubot (Oh|You) <text> (Please|Tell) <text> - Willy Wonka
# hubot <text> you're gonna have a bad time - Bad Time Ski Instructor
# hubot one does not simply <text> - Lord of the Rings Boromir
+# hubot it looks like (you|you're) <text> - Generates Clippy
#
# Author:
# skalnik
@@ -102,6 +103,11 @@ module.exports = (robot) ->
regex: /(grumpy cat) (.*),(.*)/i,
generatorID: 1590955,
imageID: 6541210
+ },
+ {
+ regex: /(it looks like you're|it looks like you) (.*)/i,
+ generatorID: 20469,
+ imageID: 1159769
}
]
@@ -0,0 +1,62 @@
+# Description:
+# Replaces default `redis-brain` with MongoDB one. Useful
+# to those who wants to have persistence on completely free
+# Heroku account.
+#
+# Dependencies:
+# "mongodb": "*"
+#
+# Configuration:
+# MONGOLAB_URI
+#
+# Commands:
+# None
+#
+# Author:
+# juancoen, darvin
+#
+
+
+Url = require "url"
+MongoClient = require('mongodb').MongoClient
+
+# sets up hooks to persist the brain into redis.
+module.exports = (robot) ->
+ mongoUrl = process.env.MONGOLAB_URI
+ # define mongo server and client for hubot database.
+ console.error "Trying to connect to #{mongoUrl}"
+ #open a connection
+ MongoClient.connect mongoUrl, (err, db) ->
+ if err
+ throw err
+ else if db
+ console.error "Connected to mongo: #{mongoUrl}"
+ # create or retrieve the collection "storage"
+ db.createCollection "storage", (err, collection) ->
+ #retrieve the one object from the database collection
+ collection.findOne {}, (err, doc) ->
+ # if an error ocurs, throw an exception
+ if err
+ throw err
+ else if doc
+ # else, merge the document into the robot brain.
+ robot.brain.mergeData doc
+
+ # listen to the "save" event of the robot's brain.
+ robot.brain.on 'save', (data) ->
+ # retrieve the collection storage.
+ db.collection 'storage', (err, collection) ->
+ # remove the object from the database.
+ collection.remove {}, (err) ->
+ if err
+ throw err
+ else
+ # save the new data provided by the robot brain.
+ collection.save data, (err) ->
+ if err
+ throw err
+
+ # listen to the "close" event of the robot's brain.
+ robot.brain.on 'close', ->
+ # close the connection
+ db.close()
@@ -10,31 +10,71 @@
# Commands:
# hubot notify me by prowl with YOUR_PROWL_API_KEY
# hubot notify me by nma with YOUR_NMA_API_KEY
+# hubot notify me by sms with 15556667890
# hubot list notifiers
#
# Author:
# marten
-
+#
+https = require "https"
Prowl = require "prowler"
QS = require "querystring"
module.exports = (robot) ->
- robot.hear /@(\w+)/i, (msg) ->
- sender = msg.message.user.name.toLowerCase()
- username = msg.match[1].toLowerCase()
- notifies = []
+ sendSms = (to, msg) ->
+ sid = process.env.HUBOT_SMS_SID
+ tkn = process.env.HUBOT_SMS_TOKEN
+ from = process.env.HUBOT_SMS_FROM
+ auth = 'Basic ' + new Buffer(sid + ':' + tkn).toString("base64")
+ data = QS.stringify
+ From: from
+ To: to
+ Body: "#{msg.message.user.name}: #{msg.message.text}"
+ unless sid
+ msg.send "Twilio SID isn't set."
+ msg.send "Please set the HUBOT_SMS_SID environment variable."
+ return
+ unless tkn
+ msg.send "Twilio token isn't set."
+ msg.send "Please set the HUBOT_SMS_TOKEN environment variable."
+ return
+
+ unless from
+ msg.send "Twilio from number isn't set."
+ msg.send "Please set the HUBOT_SMS_FROM environment variable."
+ return
+
+ msg.http("https://api.twilio.com")
+ .path("/2010-04-01/Accounts/#{sid}/SMS/Messages.json")
+ .header("Authorization", auth)
+ .header("Content-Type", "application/x-www-form-urlencoded")
+ .post(data) (err, res, body) ->
+ json = JSON.parse body
+ switch res.statusCode
+ when 201
+ msg.send "Sent sms to #{to}"
+ when 400
+ msg.send "Failed to send. #{json.message}"
+ else
+ msg.send "Failed to send."
+
+
+
+ notify = (username, msg) ->
+ notifies = []
+ console.error "Going notify #{username}"
if username == "all" or username == "everyone"
for username, apikey of robot.brain.data.notifiers
- unless username == sender
+ unless username.toLowerCase() == msg.message.user.name.toLowerCase()
notifies.push apikey
- else if apikey = robot.brain.data.notifiers[username]
+ else if apikey = robot.brain.data.notifiers[username.toLowerCase()]
notifies.push apikey
for notifier in notifies
[protocol, apikey...] = notifier.split(':')
apikey = apikey.join('')
- #msg.send("Notified #{protocol} by #{apikey}")
+ msg.send("Notified #{protocol} by #{apikey}")
switch protocol
when "prowl"
@@ -43,8 +83,12 @@ module.exports = (robot) ->
application: 'RoQua Hubot'
event: 'Mention'
description: msg.message.text
+ when "sms"
+ console.error "Sending sms"
+ sendSms apikey, msg
+
when "nma"
- params =
+ params =
apikey: apikey
application: "Hubot"
event: "Mention"
@@ -54,6 +98,55 @@ module.exports = (robot) ->
.get() (err, res, body) ->
body
+ checkIfOffline = (user, callback) ->
+ if process.env.HUBOT_HIPCHAT_TOKEN
+ options =
+ host: "api.hipchat.com"
+ port: 443
+ path: "/v1/users/show?"+QS.stringify({
+ format:"json"
+ user_id:user.id
+ auth_token:process.env.HUBOT_HIPCHAT_TOKEN
+ })
+ method: "GET"
+
+ req = https.request options, (res) ->
+ res.on "data", (data) ->
+ userData = JSON.parse(data.toString())
+ callback null, userData.user.status=="offline"
+ res.on "error", (err) ->
+ callback err
+ req.end()
+ else
+ callback null, true
+
+ robot.hear /@(\w+)/i, (msg) ->
+ sender = msg.message.user.name.toLowerCase()
+ mentionedUserName = msg.match[1].toLowerCase()
+ if mentionedUserName == "all" or mentionedUserName == "everyone"
+ notify "all", msg
+ msg.send "All notified!"
+ return
+
+
+ for userId, user of robot.brain.data.users
+ if user.mention_name==mentionedUserName
+ username=user.name
+ mentionedUserId = userId
+ theUser = user
+ if not mentionedUserId?
+ return
+ checkIfOffline theUser, (err, offline) ->
+ if err
+ throw err
+ else if offline
+ notify username, msg
+
+
+ robot.respond /do not notify me/i, (msg) ->
+ delete robot.brain.data.notifiers[msg.message.user.name.toLowerCase()]
+ msg.send "OK"
+
robot.respond /notify me by prowl with (\w+)/i, (msg) ->
apikey = msg.match[1].toLowerCase()
@@ -67,6 +160,13 @@ module.exports = (robot) ->
robot.brain.data.notifiers[msg.message.user.name.toLowerCase()] = "nma:#{apikey}"
msg.send "OK"
+ robot.respond /notify me by sms with (\d+)/i, (msg) ->
+ number = msg.match[1].toLowerCase()
+ robot.brain.data.notifiers ?= {}
+ robot.brain.data.notifiers[msg.message.user.name.toLowerCase()] = "sms:#{number}"
+ msg.send "OK"
+
+
robot.respond /list notifiers/i, (msg) ->
for username, apikey of robot.brain.data.notifiers
msg.send("I notify #{username} with #{apikey}")
@@ -124,6 +124,11 @@ views =
{{sender.login}} commented on issue {{issue.number}} on {{repo_name}} "{{{overflow issue.title 25}}}" {{issue.html_url}}
> {{{overflow comment.body 120}}}
"""
+ commit_comment:
+ """
+ {{sender.login}} commented on commit {{comment.commit_id}} on {{repo_name}} {{comment.html_url}}
+ > {{{overflow comment.body 120}}}
+ """
pull_request: (context) ->
template = switch context.action
when 'opened'
Oops, something went wrong.

0 comments on commit a8a4f58

Please sign in to comment.