3
0
mirror of https://github.com/reality/dbot.git synced 2025-04-27 18:27:54 +02: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 #!/bin/bash
cat LICENCE
git submodule init git submodule init
git submodule update git submodule update
@ -16,8 +16,20 @@ wget http://d3js.org/d3.v3.zip
unzip d3.v3.zip unzip d3.v3.zip
rm 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] #### ~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.

View File

@ -34,26 +34,42 @@ var link = function(dbot) {
}, },
'~xkcd': function(event) { '~xkcd': function(event) {
var comicId = event.params[1]; var comicId = event.params[1] || "";
if(comicId){
comicId = comicId + "/"; if(comicId == "*") {
} else { request("http://xkcd.com/info.0.json", function(error, response, body){
comicId = ""; 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"; var link = "http://xkcd.com/"+comicId+"info.0.json";
request(link, function(error, response, body) { request(link, function(error, response, body) {
try {
if (response.statusCode == "200") { if (response.statusCode == "200") {
data = JSON.parse(body); data = JSON.parse(body);
event.reply(dbot.t("xkcd",data)); event.reply(dbot.t("xkcd",data));
} else { } else {
event.reply(dbot.t("no-hits")); event.reply(dbot.t("no-hits"));
} }
} catch(err) { };
}); });
}
}, },
'~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);
@ -73,7 +89,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]);
} }

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