From f6aebb61b4c261f1e987ee3a7b687b61bf281a22 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 11 Jun 2013 17:24:42 +0000 Subject: [PATCH] initial draft of word definition thing [#503] --- install.sh | 2 +- modules/words/config.json | 3 +++ modules/words/words.js | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 modules/words/config.json create mode 100644 modules/words/words.js diff --git a/install.sh b/install.sh index 70cf91c..9c1ae68 100755 --- a/install.sh +++ b/install.sh @@ -14,7 +14,7 @@ then exit 1 fi -npm install ent underscore request sandbox express moment jade@0.25 +npm install wordnik ent underscore request sandbox express moment jade@0.25 cd public/ wget http://twitter.github.com/bootstrap/assets/bootstrap.zip diff --git a/modules/words/config.json b/modules/words/config.json new file mode 100644 index 0000000..649e069 --- /dev/null +++ b/modules/words/config.json @@ -0,0 +1,3 @@ +{ + "api_key": "http://developer.wordnik.com/" +} diff --git a/modules/words/words.js b/modules/words/words.js new file mode 100644 index 0000000..eac90b0 --- /dev/null +++ b/modules/words/words.js @@ -0,0 +1,26 @@ +var Wordnik = require('wordnik'); + +var words = function(dbot) { + this.commands = { + '~define': function(event) { + var query = event.params[1]; + this.wn.definitions(query, function(err, defs) { + if(!err && defs[0]) { + event.reply(query + ': ' + defs[0].text); + } else { + event.reply('No definitions found for ' + query); + } + }); + } + }; + + this.onLoad = function() { + this.wn = new Wordnik({ + 'api_key': this.config.api_key + }); + }.bind(this); +}; + +exports.fetch = function(dbot) { + return new words(dbot); +};