Skip to content

Instantly share code, notes, and snippets.

@notblizzard
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save notblizzard/a191e7f1459ebd1e6d96 to your computer and use it in GitHub Desktop.
Save notblizzard/a191e7f1459ebd1e6d96 to your computer and use it in GitHub Desktop.
exports.commands = {
mb: 'musicbox',
musicbox: function (target, room, user) {
if (!this.canBroadcast()) return;
var parts = target.split(',');
if (!target) return this.sendReply("/musicbox link, link, link - parses it to be in a music box");
var str = '';
for (var x = 0; x < parts.length; x++) {
parse(parts[x]).then(function(data) {
str+=data;
});
}
this.sendReply('str is '+str);
}
};
function parse (link) {
return new Promise(function(resolve, reject) {
request(link, function(err, res, body) {
if (!err && res.statusCode == 200) {
var $ = cheerio.load(body);
var title = $("title").text();
var str = '<a href="' + link + '"><button title="' + title + '">' + title + '</a></button><br />'; //parse it now
resolve(str);
} else {
reject(str);
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment