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:
commit
be80b185ed
20
install.sh
20
install.sh
@ -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"'
|
|
||||||
|
@ -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.
|
||||||
|
@ -34,35 +34,51 @@ 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 == "*") {
|
||||||
|
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 {
|
} else {
|
||||||
comicId = "";
|
if(comicId !== "") {
|
||||||
}
|
comicId = 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 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) {
|
||||||
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 +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
|
Loading…
x
Reference in New Issue
Block a user