forked from GitHub/dbot
Merge branch 'master' of https://github.com/WelshMullet/depressionbot
This commit is contained in:
commit
63943ca2dc
@ -22,4 +22,4 @@ which was posted in the current channel.
|
|||||||
#### ~ud [headword]
|
#### ~ud [headword]
|
||||||
Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided.
|
Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided.
|
||||||
#### ~xkcd <comic ID>
|
#### ~xkcd <comic ID>
|
||||||
Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given.
|
Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given. Use '*' to return a link to a random comic.
|
||||||
|
@ -35,33 +35,47 @@ var link = function(dbot) {
|
|||||||
|
|
||||||
'~xkcd': function(event) {
|
'~xkcd': function(event) {
|
||||||
var comicId = event.params[1];
|
var comicId = event.params[1];
|
||||||
if(comicId){
|
if(comicId == "*"){
|
||||||
comicId = comicId + "/";
|
request("http://xkcd.com/info.0.json", function(error, response, body){
|
||||||
} else {
|
if (response.statusCode == "200") {
|
||||||
comicId = "";
|
data = JSON.parse(body);
|
||||||
}
|
comicId = data.num;
|
||||||
var link = "http://xkcd.com/"+comicId+"info.0.json";
|
comicId = (Math.floor(Math.random() * comicId) + 1);
|
||||||
request(link, function(error, response, body) {
|
event.message = '~xkcd ' + comicId;
|
||||||
if (response.statusCode == "200") {
|
event.action = 'PRIVMSG';
|
||||||
data = JSON.parse(body);
|
event.params = event.message.split(' ');
|
||||||
event.reply(dbot.t("xkcd",data));
|
dbot.instance.emit(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else {
|
||||||
|
if(comicId){
|
||||||
|
comicId = comicId + "/";
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t("no-hits"));
|
comicId = "";
|
||||||
}
|
}
|
||||||
});
|
var link = "http://xkcd.com/"+comicId+"info.0.json";
|
||||||
|
request(link, function(error, response, body) {
|
||||||
|
if (response.statusCode == "200") {
|
||||||
|
data = JSON.parse(body);
|
||||||
|
event.reply(dbot.t("xkcd",data));
|
||||||
|
} else {
|
||||||
|
event.reply(dbot.t("no-hits"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'~ud': function(event) {
|
'~ud': function(event) {
|
||||||
var query = event.input[1];
|
var query = event.input[1];
|
||||||
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
|
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
|
||||||
request(reqUrl, function(error, response, body) {
|
request(reqUrl, function(error, response, body) {
|
||||||
try {
|
try {
|
||||||
var result = JSON.parse(body);
|
var result = JSON.parse(body);
|
||||||
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
|
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
|
||||||
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
|
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
|
||||||
} else {
|
} else {
|
||||||
event.reply(event.user + ': No definition found.');
|
event.reply(event.user + ': No definition found.');
|
||||||
}
|
}
|
||||||
} catch(err) { }
|
} catch(err) { }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,7 +87,6 @@ var link = function(dbot) {
|
|||||||
var urlMatches = event.message.match(this.urlRegex);
|
var urlMatches = event.message.match(this.urlRegex);
|
||||||
if(urlMatches !== null) {
|
if(urlMatches !== null) {
|
||||||
this.links[event.channel.name] = urlMatches[0];
|
this.links[event.channel.name] = urlMatches[0];
|
||||||
|
|
||||||
if(dbot.config.link.autoTitle == true) {
|
if(dbot.config.link.autoTitle == true) {
|
||||||
this.fetchTitle(event, urlMatches[0]);
|
this.fetchTitle(event, urlMatches[0]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user