Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 33 lines (29 sloc) 0.894 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
# Description:
# Find a Drupal module using modulepuppy.heroku.com
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot there's a module for <that>
# hubot module me <something> - Returns links to modules or themes on drupal.org
#
# Author:
# henrrrik

module.exports = (robot) ->
  robot.hear /there's a module for (.*)/i, (msg) ->
    puppySearch msg, msg.match[1]

  robot.respond /module me (.*)/i, (msg) ->
    puppySearch msg, msg.match[1]

puppySearch = (msg, query) ->
  msg.http('http://modulepuppy.heroku.com/search.json')
    .query(query: query)
    .get() (err, res, body) ->
      results = JSON.parse(body)
      modules=[]
      for result in results[0..30]
        modules.push "#{result.project.title}: #{result.project.link}"
      if modules.length>0 then msg.send modules.join('\n') else msg.send "Actually, there isn't a module for that!"
Something went wrong with that request. Please try again.