-
-
Save robotlolita/a0ce88a5c382b8dd8bee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 parsedParts = parts.map(parse); | |
Promise.all(parsedParts).then(function(parts) { | |
var str = parts.join(''); | |
this.sendReply('str is ' + str); | |
}.bind(this)) | |
} | |
}; | |
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