JSFiddle - React, Tailwind, and code Playground
by somekittens
JavaScript
// Gets a XKCD comic-type thing
bot.addCommand({
name: 'xkcd',
fun: function ( args, cb ) {
props = args.parse();
// They want a random XKCD
if ( !props[0] || props[0] === 'new' ) {
IO.jsonp({
url : 'http://dynamic.xkcd.com/api-0/jsonp/comic',
jsonpName : 'callback',
fun : finishXKCD
});
function finishXKCD ( resp ) {
if ( resp.responseStatus !== 200 ) {
cb( 'Mr. Munroe is on vacation, leave a message at the \*beep\*');
} else {
var maxID = resp.num;
cb( 'http://xkcd.com/' + Math.rand( 1, maxID ));
}
}
} else if ( props[0].test(/\d{1-4}/) ) {
cb( 'http://xkcd.com/' + props[0] );
} else {
cb( 'Clearly, you\'re not geeky enough for XKCD.' );
}
},
description: 'Returns an XKCD. Call with no args for random, `new` for latest, or a number for that comic',
async: true
});