{"size": 1495, "ext": "js", "max_stars_repo_path": "plugins/search/spotify.js", "max_stars_repo_name": "KartikTalwar/Ned", "max_stars_repo_stars_event_min_datetime": "2016-07-20T15:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-20T15:20:29.000Z", "max_issues_repo_path": "plugins/search/spotify.js", "max_issues_repo_name": "KartikTalwar/Ned", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "plugins/search/spotify.js", "max_forks_repo_name": "KartikTalwar/Ned", "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": 24.9166666667, "max_line_length": 73, "alphanum_fraction": 0.3806020067}
var plugin = {
              name        : 'spotify',
              trigger     : ['spot me', 'spot ', 'spotify', 'sp '],
              enabled     : 'true',
              fuzzy       : 'true',
              description : 'Returns the spotify url of a song',
              usage       : 'ned spot me everlong'
             };

module.exports.plugin = plugin;

module.exports[plugin.name] = function(get)
{
    if(get.isEmpty)
    {
        sendMessage(Util.errorMessage() + "Please check your input");
    }
    else
    {
        var input = Util.padd(get.message);

        var httpRequestParams = 
        {
            host : "ws.spotify.com",
            port : 80,
            path : "/search/1/track?q=" + input
        };

        http.get(httpRequestParams, function(res) 
        {
            var data = '';

            res.on('data', function(chunk) 
            {
                data += chunk;
            });
            
            res.on('end', function(chunk) 
            {
                try 
                {
                    var id = Util.cut('spotify:track:', '"', data);

                    if(id.length > 10)
                    {
                        response = "http://open.spotify.com/track/" + id;
                        sendMessage(response);
                    }
                }
                catch(err)
                {
                    sendMessage("(facepalm) Error");
                }
            });
        });
    }

    return true;
}
