mirror of
https://github.com/reality/dbot.git
synced 2025-02-17 14:01:04 +01:00
fixed xkcd random and updated readme for link
This commit is contained in:
parent
73e9b21824
commit
67d7abbf84
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "testressionbot",
|
"name": "welshtestbot",
|
||||||
"servers": {
|
"servers": {
|
||||||
"freenode": {
|
"freenode": {
|
||||||
"server": "irc.freenode.net",
|
"server": "irc.aberwiki.org",
|
||||||
"port": 6667,
|
"port": 6667,
|
||||||
"nickserv": "nickserv",
|
"nickserv": "nickserv",
|
||||||
"password": "lolturtles",
|
"password": "",
|
||||||
"channels": [
|
"channels": [
|
||||||
"#realitest"
|
"#lolhax"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -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.
|
||||||
|
@ -21,6 +21,19 @@ var link = function(dbot) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function outputComic(comicId,event){
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var commands = {
|
var commands = {
|
||||||
'~title': function(event) {
|
'~title': function(event) {
|
||||||
var link = this.links[event.channel.name];
|
var link = this.links[event.channel.name];
|
||||||
@ -35,27 +48,25 @@ var link = function(dbot) {
|
|||||||
|
|
||||||
'~xkcd': function(event) {
|
'~xkcd': function(event) {
|
||||||
var comicId = event.params[1];
|
var comicId = event.params[1];
|
||||||
if(comicId){
|
|
||||||
comicId = comicId + "/";
|
|
||||||
} else {
|
|
||||||
comicId = "";
|
|
||||||
}
|
|
||||||
var link = "http://xkcd.com/"+comicId+"info.0.json";
|
|
||||||
|
|
||||||
if(comicId == "*"){
|
if(comicId == "*"){
|
||||||
link = "http://dynamic.xkcd.com/random/comic";
|
request("http://xkcd.com/info.0.json", function(error, response, body){
|
||||||
request(link, function(error, response, body)
|
|
||||||
link = response.location + "info.0.json";
|
|
||||||
}
|
|
||||||
|
|
||||||
request(link, function(error, response, body) {
|
|
||||||
if (response.statusCode == "200") {
|
if (response.statusCode == "200") {
|
||||||
data = JSON.parse(body);
|
data = JSON.parse(body);
|
||||||
event.reply(dbot.t("xkcd",data));
|
comicId = data.num;
|
||||||
} else {
|
comicId = Math.floor(Math.random() * comicId);
|
||||||
event.reply(dbot.t("no-hits"));
|
comicId++;
|
||||||
|
comicId = comicId + "/";
|
||||||
|
outputComic(comicId,event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}else if(comicId){
|
||||||
|
comicId = comicId + "/";
|
||||||
|
outputComic(comicId,event);
|
||||||
|
} else {
|
||||||
|
comicId = "";
|
||||||
|
outputComic(comicId,event);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'~ud': function(event) {
|
'~ud': function(event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user