Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakaria Zajac authored and Zakaria Zajac committed Oct 30, 2011
2 parents ec50aa0 + 9a8c074 commit 824dd41
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 17 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
v1.1.4
======
* hubot define me - Pete Nicholls <pete@metanation.com>
* google directions support - Zakaria Zajac <zdzajac@gmail.com>
* hubot vanity me fixup - Alex Whitman <alex@alexwhitman.com>
* newrelic performance support - Brian Doll <brian@emphaticsolutions.com>
* sendgrid status support - Jeff Fraser <sixfeetover@gmail.com>
* hubot show me stories for <project> - Assaf Arkin <assaf@labnotes.org>
* fix wolfram version to support heroku's node - Simon Horne <soulware@gmail.com>
* add bing search support - Brandon Satrom <brsatrom@microsoft.com>
* add github issues support - Assaf Arkin <assaf@labnotes.org>

v1.0.4
======

Expand Down
7 changes: 4 additions & 3 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-scripts",
"version": "1.1.3",
"version": "1.1.4",
"author": "hubot",
"keywords": "hubot plugin scripts campfire bot robot",
"description": "Allows you to open in to a variety of scripts",
Expand All @@ -19,9 +19,10 @@
"redis": "0.6.7",
"jsdom": "==0.2.0",
"xml2js": "0.1.x",
"wolfram": "0.1.0",
"wolfram": "0.1.1",
"soupselect": "0.2.0",
"htmlparser": "1.7.x"
"htmlparser": "1.7.x",
"sprintf": "0.1.1"
},

"directories": {
Expand Down
15 changes: 15 additions & 0 deletions src/scripts/achievement_unlocked.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# achievement get <achievement> [achiever's gravatar email] - life goals are in reach.
#
module.exports = (robot) ->
robot.hear /achievement (get|unlock(ed)?) (.+?)(\s*[^@\s]+@[^@\s]+)?\s*$/i, (msg) ->
caption = msg.match[3]
email = msg.match[4]
url = "http://achievement-unlocked.heroku.com/xbox/#{escape(caption)}.png"
if email
url += "?email=#{escape(email.trim())}.png"
msg.send(url)

robot.hear /acheivement (get|unlock(ed)?)/i, (msg) ->
url = "http://achievement-unlocked.heroku.com/xbox/#{escape("Bane of Daniel Webster")}.png"
msg.send(url)
7 changes: 7 additions & 0 deletions src/scripts/bees.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bees are insane
#
# bees - Oprah at her finest, or a good way to turn the fans on coworkers machines

module.exports = (robot) ->
robot.respond /bees/i, (message) ->
message.send "http://thechive.files.wordpress.com/2010/11/oprah-bees.gif"
15 changes: 15 additions & 0 deletions src/scripts/bing.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Returns the URL of the first bing hit for a query
#
# bing me <query> - Bings <query> & returns 1st result's URL

module.exports = (robot) ->
robot.respond /(bing)( me)? (.*)/i, (msg) ->
bingMe msg, msg.match[3], (url) ->
msg.send url

bingMe = (msg, query, cb) ->
msg.http('http://www.bing.com/search')
.query(q: query)
.get() (err, res, body) ->
cb body.match(/<div class="sb_tlst"><h3><a href="([^"]*)"/)?[1] || "Sorry, Bing had zero results for '#{query}'"

10 changes: 7 additions & 3 deletions src/scripts/github-issues.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ module.exports = (robot) ->
msg.send "GitHub says: #{err}"
return
issues = JSON.parse(body)
for issue in issues
labels = ("##{label.name}" for label in issue.labels)
msg.send "[#{issue.number}] #{issue.title} #{labels.join(" ")}"
if issues.length == 0
msg.send "Achievement unlocked: issues zero!"
else
for issue in issues
labels = ("##{label.name}" for label in issue.labels).join(" ")
assignee = if issue.assignee then " (#{issue.assignee.login})" else ""
msg.send "[#{issue.number}] #{issue.title} #{labels}#{assignee} = #{issue.html_url}"

4 changes: 2 additions & 2 deletions src/scripts/meme_generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Y U NO <text> - Generates the Y U NO GUY with the bottom caption
# of <text>
#
# I don't always <something>
# but when I do <text> - Generates The Most Interesting man in the World
# I don't always <something> but when i do <text> - Generates The Most Interesting man in the World
#
# <text> ORLY? - Generates the ORLY? owl with the top caption of <text>
#
# <text> (SUCCESS|NAILED IT) - Generates success kid with the top caption of <text>
#
# <text> ALL the <things> - Generates ALL THE THINGS

module.exports = (robot) ->
robot.respond /Y U NO (.+)/i, (msg) ->
Expand Down
36 changes: 36 additions & 0 deletions src/scripts/newrelic.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Display current app performance stats from New Relic
#
# You need to set the following variables:
# HUBOT_NEWRELIC_ACCOUNT_ID = "<Account ID>"
# HUBOT_NEWRELIC_APP_ID = "<Application ID>"
# HUBOT_NEWRELIC_API_KEY = "<API Key>"
#
# How to find these settings:
# After signing into New Relic, select your application
# Given: https://rpm.newrelic.com/accounts/xxx/applications/yyy
# xxx is your Account ID and yyy is your App ID
# Account Settings > API + Web Integrations > API Access > "API key"
#
# TODO:
# - Allow hubot to display all app stats for a given account using the View Applications API call
# https://github.com/newrelic/newrelic_api
# - Allow you to specify the name of the app to fetch metrics for:
# hubot newrelic me "My App Name"
#
# hubot <newrelic me> - Returns summary application stats from New Relic
module.exports = (robot) ->
robot.respond /newrelic me/i, (msg) ->
accountId = process.env.HUBOT_NEWRELIC_ACCOUNT_ID
appId = process.env.HUBOT_NEWRELIC_APP_ID
apiKey = process.env.HUBOT_NEWRELIC_API_KEY
Parser = require("xml2js").Parser

msg.http("https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}/threshold_values.xml?api_key=#{apiKey}")
.get() (err, res, body) ->
if err
msg.send "New Relic says: #{err}"
return
(new Parser).parseString body, (err, json)->
for threshold_value in json['threshold_value']
msg.send " #{threshold_value['@']['name']} : #{threshold_value['@']['formatted_metric_value']}"
msg.send " https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}"
41 changes: 41 additions & 0 deletions src/scripts/pivotal.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Get current stories from PivotalTracker
#
# You need to set the following variables:
# HUBOT_PIVOTAL_TOKEN = <API token>
#
# If you're working on a single project, you can set it once:
# HUBOT_PIVOTAL_PROJECT = <project name>
#
# Otherwise, include the project name in your message to Hubot.
#
# show me stories for <project> -- shows current stories being worked on
module.exports = (robot) ->
robot.respond /show\s+(me\s+)?stories\s+(for\s+)?(.*)/i, (msg)->
Parser = require("xml2js").Parser
token = process.env.HUBOT_PIVOTAL_TOKEN
project_name = msg.match[3]
if project_name == ""
project_name = RegExp(process.env.HUBOT_PIVOTAL_PROJECT, "i")
else
project_name = RegExp(project_name + ".*", "i")

msg.http("http://www.pivotaltracker.com/services/v3/projects").headers("X-TrackerToken": token).get() (err, res, body) ->
if err
msg.send "Pivotal says: #{err}"
return
(new Parser).parseString body, (err, json)->
for project in json.project
if project_name.test(project.name)
msg.http("https://www.pivotaltracker.com/services/v3/projects/#{project.id}/stories").headers("X-TrackerToken": token).query(filter: "state:unstarted,started,finished,delivered").get() (err, res, body) ->
if err
msg.send "Pivotal says: #{err}"
return

(new Parser).parseString body, (err, json)->
for story in json.story
message = "##{story.id['#']} #{story.name}"
message += " (#{story.owned_by})" if story.owned_by
message += " is #{story.current_state}" if story.current_state && story.current_state != "unstarted"
msg.send message
return
msg.send "No project #{project_name}"
6 changes: 2 additions & 4 deletions src/scripts/remind.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ class Reminders
@cache = []
@current_timeout = null

loadReminders = =>
@robot.brain.on 'loaded', =>
if @robot.brain.data.reminders
@cache = @robot.brain.data.reminders
@queue()
setTimeout loadReminders, 5000 # Hacky until there's some kind of 'loaded' notification

add: (reminder) ->
@cache.push reminder
Expand Down Expand Up @@ -58,7 +57,7 @@ class Reminder
seconds:
value: 0
regex: "seconds?|secs?"

for period of periods
pattern = new RegExp('^.*?([\\d\\.]+)\\s*(?:(?:' + periods[period].regex + ')).*$', 'i')
matches = pattern.exec(@time)
Expand All @@ -81,4 +80,3 @@ module.exports = (robot) ->
reminder = new Reminder msg.message.user, time, action
reminders.add reminder
msg.send 'I\'ll remind you to ' + action + ' on ' + reminder.dueDate()

71 changes: 71 additions & 0 deletions src/scripts/sendgrid.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Basic SendGrid statistics.
#
# Set HUBOT_SENDGRID_USER to your SendGrid username (the same as you use to log in to sendgrid.com)
# Set HUBOT_SENDGRID_KEY to your SendGrid password (the same as you use to log in to sendgrid.com)
#
# sendgrid total - total sendgrid usage for the account
# sendgrid today - Total usage for today
# sendgrid c[ategory] <category> - Today's usage for the given category

env = process.env

module.exports = (robot) ->
if env.HUBOT_SENDGRID_USER and env.HUBOT_SENDGRID_KEY
robot.respond /(sendgrid)( me)? today/i, (msg) ->
opts =
days: 0
query msg, opts, (json) ->
msg.send formatResponse(json[0])

robot.respond /(sendgrid)( me)? total/i, (msg) ->
opts =
aggregate: 1
query msg, opts, (json) ->
msg.send formatResponse(json)

robot.respond /(sendgrid)( me)? c(ategory)? (.*)/i, (msg) ->
category = msg.match[4]
msg.send "Category: #{category}"
opts =
days: 0
category: [category]
query msg, opts, (json) ->
msg.send formatResponse(json[0])

query = (msg, opts, callback) ->
opts.api_user = env.HUBOT_SENDGRID_USER
opts.api_key = env.HUBOT_SENDGRID_KEY
msg.http("https://sendgrid.com/api/stats.get.json")
.query(opts)
.get() (err, res, body) ->
callback JSON.parse(body)

stats =
requests: 'Requests'
delivered: 'Delivered'

bounces: 'Bounces'
repeat_bounces: 'Repeat Bounces'

invalid_email: 'Invalid Emails'

opens: 'Opens'
unique_opens: 'Unique Opens'

clicks: 'Clicks'
unique_clicks: 'Unique Clicks'

unsubscribes: 'Unsubscribes'
repeat_unsubscribes: 'Repeat Unsubscribes'

blocked: 'Blocked'
spam_drop: 'Spam Drop'

spamreports: 'Spam Reports'
repeat_spamreports: 'Repeat Spam Reports'

formatResponse = (json) =>
details = for stat, description of stats
" #{description}: #{json[stat]}"
details.unshift "Stats for #{json.date}:"
details.join("\n")
3 changes: 1 addition & 2 deletions src/scripts/vanity.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

Path = require "path"
sprintf = require(Path.resolve(Path.join(__dirname, "..", "lib", "sprintf"))).sprintf
sprintf = require("sprintf").sprintf

countFollowers = (msg, ids, cb) ->
counts = []
Expand Down Expand Up @@ -55,4 +55,3 @@ module.exports = (robot) ->
msg.send output
else
msg.reply "Sorry, not right now. Twitter's returning a #{res.statusCode} error"

6 changes: 3 additions & 3 deletions src/scripts/wolfram.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (robot) ->
robot.respond /question (.*)$/i, (msg) ->
Wolfram.query msg.match[1], (e, result) ->
# console.log result
if result.length > 0
msg.send result[1]['subpods'][0]['value']
if result and result.length > 0
msg.reply result[1]['subpods'][0]['value']
else
msg.send 'Hmm...not sure. Maybe I don\'t understand the question.'
msg.reply 'Hmm...not sure. Maybe I don\'t understand the question.'
34 changes: 34 additions & 0 deletions src/scripts/wordnik.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Dictionary definitions with the Wordnik API. You'll need an API key from http://developer.wordnik.com/
#
# define me <word> - Grabs a dictionary definition of a word.
module.exports = (robot) ->
robot.respond /define( me)? (.*)/i, (msg) ->

if process.env.WORDNIK_API_KEY == undefined
msg.send "Missing WORDNIK_API_KEY env variable."
return

word = msg.match[2]

msg.http("http://api.wordnik.com/v4/word.json/#{escape(word)}/definitions")
.header('api_key', process.env.WORDNIK_API_KEY)
.get() (err, res, body) ->
definitions = JSON.parse(body)

if definitions.length == 0
msg.send "No definitions for \"#{word}\" found."
else
reply = "Definitions for \"#{word}\":\n"

lastSpeechType = null
definitions = definitions.forEach (def) ->
# Show the part of speech (noun, verb, etc.) when it changes
if def.partOfSpeech != lastSpeechType
reply += " (#{def.partOfSpeech})\n" if def.partOfSpeech != undefined

lastSpeechType = def.partOfSpeech

reply += " - #{def.text}\n"

msg.send reply

27 changes: 27 additions & 0 deletions src/scripts/xkcd.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Grab XKCD comic image urls
#
# xkcd - The latest XKCD comic
# xkcd <num> - XKCD comic matching the supplied number
#
# Examples
#
# xkcd 149
# # => Sandwich - http://imgs.xkcd.com/comics/sandwich.png
# # => Proper User Policy apparently means Simon Says.
#
module.exports = (robot) ->
robot.respond /xkcd\s?(\d+)?/i, (msg) ->
if msg.match[1] == undefined
num = ''
else
num = "#{msg.match[1]}/"

msg.http("http://xkcd.com/#{num}info.0.json")
.get() (err, res, body) ->
if res.statusCode == 404
msg.send 'Comic not found.'
else
object = JSON.parse(body)
msg.send object.alt
msg.send object.title
msg.send object.img

0 comments on commit 824dd41

Please sign in to comment.