Skip to content

Instantly share code, notes, and snippets.

@NotBlizzard
Last active Aug 29, 2015
Embed
What would you like to do?
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