diff --git a/install.sh b/install.sh index 42cf7ec..8a8d85d 100755 --- a/install.sh +++ b/install.sh @@ -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"' diff --git a/modules/link/README.md b/modules/link/README.md index 21de8ef..fed0a33 100644 --- a/modules/link/README.md +++ b/modules/link/README.md @@ -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 -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. diff --git a/modules/link/link.js b/modules/link/link.js index d684cf3..b72e8e8 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -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]); } diff --git a/modules/stats b/modules/stats index ea795e4..171d246 160000 --- a/modules/stats +++ b/modules/stats @@ -1 +1 @@ -Subproject commit ea795e4d17aa500923468366e73a10f6fbc94ade +Subproject commit 171d246b744ad59a66fcab37b8c9ccde793d9213