~xkcd command now finds relevant XKCDs when given text instead of a number

This commit is contained in:
Scritches 2018-04-26 17:14:18 -04:00
parent c298813b28
commit 0c8c377b08

View File

@ -110,23 +110,47 @@ var link = function(dbot) {
} catch(err) { }; } catch(err) { };
}); });
} else { } else {
if(comicId !== "") { if (isNaN(parseInt(comicId))) {
comicId = comicId + "/"; var relevantUrl = 'https://relevantxkcd.appspot.com/process';
} request({
url: relevantUrl,
var link = "http://xkcd.com/"+comicId+"info.0.json"; qs: {
request(link, function(error, response, body) { action:'xkcd',
try { query: comicId
if (response.statusCode == "200") {
data = JSON.parse(body);
event.reply(dbot.t("xkcd", data));
} else {
event.reply(dbot.t("no-hits"));
} }
} catch(err) { }; }, function(err, res, body) {
}); comicId = body.split(' ').slice(2)[0].trim();
var link = "http://xkcd.com/"+comicId+"/info.0.json";
request(link, function(error, response, body) {
try {
if (response.statusCode == "200") {
data = JSON.parse(body);
event.reply(dbot.t("xkcd", data));
} else {
event.reply(dbot.t("no-hits"));
}
} catch(err) { };
});
});
} else {
if(comicId !== "") {
comicId = comicId + "/";
}
var link = "http://xkcd.com/"+comicId+"info.0.json";
request(link, function(error, response, body) {
try {
if (response.statusCode == "200") {
data = JSON.parse(body);
event.reply(dbot.t("xkcd", data));
} else {
event.reply(dbot.t("no-hits"));
}
} catch(err) { };
});
}
} }
}, },
'~ud': function(event) { '~ud': function(event) {