3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

Merge remote branch 'upstream/master' into rain

This commit is contained in:
Douglas Gardner 2013-01-31 19:48:18 +00:00
commit be80b185ed
4 changed files with 60 additions and 33 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash
cat LICENCE
git submodule init
git submodule update
@ -16,8 +16,20 @@ wget http://d3js.org/d3.v3.zip
unzip d3.v3.zip
rm d3.v3.zip
cd ..
cd ../..
cp config.json.sample config.json
if [ ! -f config.json ];
then
echo 'Creating configuration file...'
cp config.json.sample config.json
vim config.json
fi
read -p "Setup complete. Run depressionbot now? [y/N]"
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo 'Okay. To run the bot, use "node run.js"'
exit
fi
node run.js
echo 'Setup complete. Now edit config.json with your preferences and run the bot with "node run.js"'

View File

@ -22,4 +22,4 @@ which was posted in the current channel.
#### ~ud [headword]
Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided.
#### ~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.

View File

@ -20,7 +20,7 @@ var link = function(dbot) {
}
});
};
var commands = {
'~title': function(event) {
var link = this.links[event.channel.name];
@ -34,35 +34,51 @@ var link = function(dbot) {
},
'~xkcd': function(event) {
var comicId = event.params[1];
if(comicId){
comicId = comicId + "/";
} else {
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"));
}
});
},
var comicId = event.params[1] || "";
if(comicId == "*") {
request("http://xkcd.com/info.0.json", function(error, response, body){
try {
if(response.statusCode == "200") {
data = JSON.parse(body);
event.params[1] = (Math.floor(Math.random() * data.num) + 1);
dbot.commands['~xkcd'](event);
}
} 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) {
var query = event.input[1];
var query = event.input[1];
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
request(reqUrl, function(error, response, body) {
try {
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
} else {
event.reply(event.user + ': No definition found.');
}
} catch(err) { }
try {
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
} else {
event.reply(event.user + ': No definition found.');
}
} catch(err) { }
});
}
};
@ -73,7 +89,6 @@ var link = function(dbot) {
var urlMatches = event.message.match(this.urlRegex);
if(urlMatches !== null) {
this.links[event.channel.name] = urlMatches[0];
if(dbot.config.link.autoTitle == true) {
this.fetchTitle(event, urlMatches[0]);
}

@ -1 +1 @@
Subproject commit ea795e4d17aa500923468366e73a10f6fbc94ade
Subproject commit 171d246b744ad59a66fcab37b8c9ccde793d9213