Skip to content
Browse files

Merge pull request #680 from Iristyle/httpinfo-ignores

Http-info now accepts environment variables to ignore more urls
  • Loading branch information...
2 parents 7a6a70c + 406d58b commit babe278a3e5df4db8b95910e7973174e31f747b3 Tom Bell committed Jan 10, 2013
Showing with 23 additions and 3 deletions.
  1. +23 −3 src/scripts/http-info.coffee
View
26 src/scripts/http-info.coffee
@@ -5,22 +5,42 @@
# "jsdom": "0.2.15"
#
# Configuration:
-# None
+#
+# Optional Configuration:
+# HUBOT_HTTP_INFO_IGNORE_URLS - RegEx used to exclude Urls
+# HUBOT_HTTP_INFO_IGNORE_USERS - Comma separated list of users to ignore
#
# Commands:
# http(s)://<site> - prints the title and meta description for sites linked.
#
# Author:
# ajacksified
-jsdom = require('jsdom')
+jsdom = require 'jsdom'
+_ = require 'underscore'
module.exports = (robot) ->
+ ignoredusers = []
+ if process.env.HUBOT_HTTP_INFO_IGNORE_USERS?
+ ignoredusers = process.env.HUBOT_HTTP_INFO_IGNORE_USERS.split(',')
+
robot.hear /http(s?):\/\/(.*)/i, (msg) ->
url = msg.match[0]
- unless url.match(/\.(png|jpg|jpeg|gif|txt|zip|tar\.bz|js|css)/) # filter out some common files from trying
+ username = msg.message.user.name
+ if _.some(ignoredusers, (user) -> user == username)
+ console.log 'ignoring user due to blacklist:', username
+ return
+
+ # filter out some common files from trying
+ ignore = url.match(/\.(png|jpg|jpeg|gif|txt|zip|tar\.bz|js|css)/)
+
+ ignorePattern = process.env.HUBOT_HTTP_INFO_IGNORE_URLS
+ if !ignore && ignorePattern
+ ignore = url.match(ignorePattern)
+
+ unless ignore
jsdom.env(
html: msg.match[0]
scripts: [

0 comments on commit babe278

Please sign in to comment.
Something went wrong with that request. Please try again.