{"size": 1142, "ext": "js", "max_stars_repo_path": "dist/giphy.js", "max_stars_repo_name": "junhui/hubot-scripts", "max_stars_repo_stars_event_min_datetime": "2018-07-28T05:08:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-28T05:08:20.000Z", "max_issues_repo_path": "dist/giphy.js", "max_issues_repo_name": "junhui/hubot-scripts", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dist/giphy.js", "max_forks_repo_name": "junhui/hubot-scripts", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.3921568627, "max_line_length": 87, "alphanum_fraction": 0.5945709282}
// Description:
//   A way to search images on giphy.com

// Configuration:
//   HUBOT_GIPHY_API_KEY

// Commands:
//   hubot gif me <query> - Returns an animated gif matching the requested search term.
var giphy, giphyMe;

giphy = {
  api_key: process.env.HUBOT_GIPHY_API_KEY,
  base_url: 'http://api.giphy.com/v1'
};

module.exports = function(robot) {
  return robot.respond(/(gif|giphy)( me)? (.*)/i, function(msg) {
    return giphyMe(msg, msg.match[3], function(url) {
      return msg.send(url);
    });
  });
};

giphyMe = function(msg, query, cb) {
  var endpoint, url;
  endpoint = '/gifs/search';
  url = `${giphy.base_url}${endpoint}`;
  return msg.http(url).query({
    q: query,
    api_key: giphy.api_key
  }).get()(function(err, res, body) {
    var e, image, images, response;
    response = void 0;
    try {
      response = JSON.parse(body);
      images = response.data;
      if (images.length > 0) {
        image = msg.random(images);
        cb(image.images.original.url);
      }
    } catch (error) {
      e = error;
      response = void 0;
      cb('Error');
    }
    if (response === void 0) {

    }
  });
};
