From af125cab4d49c5165e71307130eb243f2fb0ec46 Mon Sep 17 00:00:00 2001 From: Adam Becker Date: Sat, 4 Jun 2016 07:41:22 -0700 Subject: [PATCH] use slack adapter, remove unused scripts --- Procfile | 2 +- README.md | 3 - external-scripts.json | 2 +- package.json | 3 +- scripts/google-images.coffee | 44 ------------- scripts/help.coffee | 83 ------------------------- scripts/maps.coffee | 26 -------- scripts/math.coffee | 22 ------- scripts/todo_reminders.coffee | 62 ------------------ scripts/translate.coffee | 114 ---------------------------------- scripts/youtube.coffee | 28 --------- 11 files changed, 4 insertions(+), 385 deletions(-) delete mode 100644 scripts/google-images.coffee delete mode 100644 scripts/help.coffee delete mode 100644 scripts/maps.coffee delete mode 100644 scripts/math.coffee delete mode 100644 scripts/todo_reminders.coffee delete mode 100644 scripts/translate.coffee delete mode 100644 scripts/youtube.coffee diff --git a/Procfile b/Procfile index cbc8ad8..29e8984 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -hubot: bin/hubot --adapter irc --alias // +hubot: bin/hubot --adapter slack --alias // diff --git a/README.md b/README.md index c8f7290..5e5ea99 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,6 @@ can be something like Campfire or IRC. There are a number of third party adapters that the community have contributed. Check [Hubot Adapters][hubot-adapters] for the available ones. -We're using the IRC adapter to connect Hubot to Slack. The login details -are in Meldium. - If you would like to run a non-Campfire or shell adapter you will need to add the adapter package as a dependency to the `package.json` file in the `dependencies` section. diff --git a/external-scripts.json b/external-scripts.json index c3309fa..853fae1 100644 --- a/external-scripts.json +++ b/external-scripts.json @@ -1 +1 @@ -["hubot-buffer", "hubot-github-todos", "hubot-cron"] +["hubot-buffer", "hubot-github-todos", "hubot-cron", "hubot-help"] diff --git a/package.json b/package.json index 3b90c8b..a174829 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,9 @@ "hubot-buffer": "0.0.4", "hubot-cron": "^0.2.7", "hubot-github-todos": "0.4.0", - "hubot-irc": "^0.2.7", + "hubot-help": "^0.2.0", "hubot-scripts": "2.5.11", + "hubot-slack": "^3.4.2", "nightmare": "^1.7.0", "prettyjson": "^1.1.3", "request": "~2.34.0", diff --git a/scripts/google-images.coffee b/scripts/google-images.coffee deleted file mode 100644 index 8f4586d..0000000 --- a/scripts/google-images.coffee +++ /dev/null @@ -1,44 +0,0 @@ -# Description: -# A way to interact with the Google Images API. -# -# Commands: -# hubot image me - The Original. Queries Google Images for and returns a random top result. -# hubot animate me - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead. -# hubot mustache me - Adds a mustache to the specified URL. -# hubot mustache me - 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, msg.match[2], true, (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, false, true, (url) -> - msg.send "#{mustachify}#{url}" - -imageMe = (msg, query, animated, faces, cb) -> - cb = animated if typeof animated == 'function' - cb = faces if typeof faces == 'function' - q = v: '1.0', rsz: '8', q: query, safe: 'active' - q.imgtype = 'animated' if typeof animated is 'boolean' and animated is true - q.imgtype = 'face' if typeof faces is 'boolean' and faces is true - msg.http('http://ajax.googleapis.com/ajax/services/search/images') - .query(q) - .get() (err, res, body) -> - images = JSON.parse(body) - images = images.responseData?.results - if images?.length > 0 - image = msg.random images - cb "#{image.unescapedUrl}#.png" - diff --git a/scripts/help.coffee b/scripts/help.coffee deleted file mode 100644 index 2ff4fa2..0000000 --- a/scripts/help.coffee +++ /dev/null @@ -1,83 +0,0 @@ -# Description: -# Generates help commands for Hubot. -# -# Commands: -# hubot help - Displays all of the help commands that Hubot knows about. -# hubot help - Displays all help commands that match . -# -# URLS: -# /hubot/help -# -# Notes: -# These commands are grabbed from comment blocks at the top of each file. - -helpContents = (name, commands) -> - - """ - - - #{name} Help - - - -

#{name} Help

-
- #{commands} -
- - - """ - -module.exports = (robot) -> - robot.respond /help\s*(.*)?$/i, (msg) -> - cmds = robot.helpCommands() - filter = msg.match[1] - - if filter - cmds = cmds.filter (cmd) -> - cmd.match new RegExp(filter, 'i') - if cmds.length == 0 - msg.send "No available commands match #{filter}" - return - - prefix = robot.alias or robot.name - cmds = cmds.map (cmd) -> - cmd = cmd.replace /^hubot/, prefix - cmd.replace /hubot/ig, robot.name - - emit = cmds.join "\n" - - msg.send emit - - robot.router.get "/#{robot.name}/help", (req, res) -> - cmds = robot.helpCommands().map (cmd) -> - cmd.replace(/&/g,'&').replace(//g,'>') - - emit = "

#{cmds.join '

'}

" - - emit = emit.replace /hubot/ig, "#{robot.name}" - - res.setHeader 'content-type', 'text/html' - res.end helpContents robot.name, emit diff --git a/scripts/maps.coffee b/scripts/maps.coffee deleted file mode 100644 index 426effa..0000000 --- a/scripts/maps.coffee +++ /dev/null @@ -1,26 +0,0 @@ -# Description: -# Interacts with the Google Maps API. -# -# Commands: -# hubot map me - 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 - diff --git a/scripts/math.coffee b/scripts/math.coffee deleted file mode 100644 index 6a85414..0000000 --- a/scripts/math.coffee +++ /dev/null @@ -1,22 +0,0 @@ -# Description: -# Allows Hubot to do mathematics. -# -# Commands: -# hubot math me - Calculate the given expression. -# hubot convert me to - Convert expression to given units. -module.exports = (robot) -> - robot.respond /(calc|calculate|calculator|convert|math|maths)( me)? (.*)/i, (msg) -> - msg - .http('https://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.' - diff --git a/scripts/todo_reminders.coffee b/scripts/todo_reminders.coffee deleted file mode 100644 index 7dff9d3..0000000 --- a/scripts/todo_reminders.coffee +++ /dev/null @@ -1,62 +0,0 @@ -IMAGE_URL = "http://f.cl.ly/items/3q1M011Q072S461s3x46/Screenshot_3_20_13_1_48_PM.png" -HUBOT_USER_ID = 542415 -ROOM_URL = "43925_hubot@conf.hipchat.com" - -request = require 'request' -_ = require 'underscore' -async = require 'async' - -module.exports = (robot) -> - return - - github = require("githubot")(robot) - - getGithubUser = (x) -> - process.env["HUBOT_GITHUB_USER_#{x.toUpperCase()}"] - - ping = -> - request "https://api.hipchat.com/v1/users/list?format=json&auth_token=#{process.env['HUBOT_HIPCHAT_API_TOKEN']}", (err, res, body) -> - allUsers = JSON.parse(body)['users'] - - availableUsers = _.filter allUsers, (user) -> - (user.mention_name != 'sid') && - (user.id != HUBOT_USER_ID) && - (user.status in ['available', 'away']) && - getGithubUser(user.mention_name) - - showIssueFunctions = [] - - queryParams = - assignee: '*' - labels: 'current' - - for repo in (process.env['HUBOT_GITHUB_TODOS_REPO'] || '').split(',') - do (repo) => - showIssueFunctions.push( (cb) => - github.get "repos/#{repo}/issues", queryParams, (data) -> - cb(null, data) - ) - - async.parallel showIssueFunctions, (err, results) => - log("ERROR: #{err}") if err - allIssues = [].concat.apply([], results) - - for key, user of availableUsers - do (key, user) -> - issueCount = _.filter(allIssues, (issue) -> - issue.assignee.login == getGithubUser(user.mention_name) - ).length - - if issueCount == 0 - robot.messageRoom ROOM_URL, "No current issues found for @#{user.mention_name}." - robot.messageRoom ROOM_URL, IMAGE_URL - console.log "#{user.mention_name} has no issues, ping is not OK!" - else if issueCount == 1 - console.log "#{user.mention_name} has one current issue, ping is OK!" - else - robot.messageRoom ROOM_URL, "http://cl.ly/image/0Z220V0O0i3j/jpeg.jpg" - robot.messageRoom ROOM_URL, "Wow, such multitask. @#{user.mention_name} has #{issueCount} issues marked as 'current'!" - console.log "#{user.mention_name} has #{issueCount} issues, ping is not OK!" - - ping() - setInterval ping, 3600000 diff --git a/scripts/translate.coffee b/scripts/translate.coffee deleted file mode 100644 index 673c2b8..0000000 --- a/scripts/translate.coffee +++ /dev/null @@ -1,114 +0,0 @@ -# Description: -# Allows Hubot to know many languages. -# -# Commands: -# hubot translate me - Searches for a translation for the and then prints that bad boy out. -# hubot translate me from into - Translates from into . Both and are optional - -languages = - "af": "Afrikaans", - "sq": "Albanian", - "ar": "Arabic", - "az": "Azerbaijani", - "eu": "Basque", - "bn": "Bengali", - "be": "Belarusian", - "bg": "Bulgarian", - "ca": "Catalan", - "zh-CN": "Simplified Chinese", - "zh-TW": "Traditional Chinese", - "hr": "Croatian", - "cs": "Czech", - "da": "Danish", - "nl": "Dutch", - "en": "English", - "eo": "Esperanto", - "et": "Estonian", - "tl": "Filipino", - "fi": "Finnish", - "fr": "French", - "gl": "Galician", - "ka": "Georgian", - "de": "German", - "el": "Greek", - "gu": "Gujarati", - "ht": "Haitian Creole", - "iw": "Hebrew", - "hi": "Hindi", - "hu": "Hungarian", - "is": "Icelandic", - "id": "Indonesian", - "ga": "Irish", - "it": "Italian", - "ja": "Japanese", - "kn": "Kannada", - "ko": "Korean", - "la": "Latin", - "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", - "ta": "Tamil", - "te": "Telugu", - "th": "Thai", - "tr": "Turkish", - "uk": "Ukrainian", - "ur": "Urdu", - "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) -> - language_choices = (language for _, language of languages).sort().join('|') - pattern = new RegExp('translate(?: me)?' + - "(?: from (#{language_choices}))?" + - "(?: (?:in)?to (#{language_choices}))?" + - '(.*)', 'i') - robot.respond pattern, (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("https://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 - }) - .header('User-Agent', 'Mozilla/5.0') - .get() (err, res, body) -> - data = body - if data.length > 4 and data[0] == '[' - parsed = eval(data) - language =languages[parsed[2]] - parsed = parsed[0] and parsed[0][0] and 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]}" - diff --git a/scripts/youtube.coffee b/scripts/youtube.coffee deleted file mode 100644 index 702c4e2..0000000 --- a/scripts/youtube.coffee +++ /dev/null @@ -1,28 +0,0 @@ -# Description: -# Messing around with the YouTube API. -# -# Commands: -# hubot youtube me - Searches YouTube for the query and returns the video embed link. -module.exports = (robot) -> - robot.respond /(youtube|yt)( me)? (.*)/i, (msg) -> - query = msg.match[3] - robot.http("http://gdata.youtube.com/feeds/api/videos") - .query({ - orderBy: "relevance" - 'max-results': 15 - alt: 'json' - q: query - }) - .get() (err, res, body) -> - videos = JSON.parse(body) - videos = videos.feed.entry - - unless videos? - msg.send "No video results for \"#{query}\"" - return - - video = msg.random videos - video.link.forEach (link) -> - if link.rel is "alternate" and link.type is "text/html" - msg.send link.href -