diff --git a/modules/words/config.json b/modules/words/config.json index b147589..a438e0c 100644 --- a/modules/words/config.json +++ b/modules/words/config.json @@ -1,3 +1,4 @@ { - "api_key": "http://developer.wordnik.com/" -} \ No newline at end of file + "api_key": "http://developer.wordnik.com/", + "outputPrefix": "\u000311words\u000f" +} diff --git a/modules/words/strings.json b/modules/words/strings.json new file mode 100644 index 0000000..1bf7b97 --- /dev/null +++ b/modules/words/strings.json @@ -0,0 +1,17 @@ +{ + "def": { + "en": "{word}: {definition}." + }, + "no_def": { + "en": "No definitions found for {word}." + }, + "no_word": { + "en": "{word} not known." + }, + "no_example": { + "en": "No examples found for {word}." + }, + "no_similar": { + "en": "No related words found for {word}" + } +} diff --git a/modules/words/words.js b/modules/words/words.js index ff5e79c..f616316 100644 --- a/modules/words/words.js +++ b/modules/words/words.js @@ -6,9 +6,12 @@ var words = function(dbot) { var query = event.params[1]; this.wn.definitions(encodeURIComponent(query), function(err, defs) { if(!err && defs[0]) { - event.reply(query + ': ' + defs[0].text); + event.reply(dbot.t('def', { + 'word': query, + 'definition': defs[0].text + })); } else { - event.reply('No definitions found for ' + query); + event.reply(dbot.t('no_def', { 'word': query })); } }); }, @@ -21,17 +24,56 @@ var words = function(dbot) { 'limit': 10 }, function(err, related) { if(related[0]) { - event.reply('Words related to ' + query + ': ' + - related[0].words.join(', ') + '.'); + event.reply(dbot.t('def', { + 'word': 'Words related to ' + query, + 'definition': related[0].words.join(', ') + '.' + })); } else { - event.reply('No similar words found.'); + event.reply(dbot.t('no_similar', { 'word': query })); } }); } else { - event.reply('Unknown word.'); + event.reply(dbot.t('no_word', { 'word': query })); } }); - + }, + + '~example': function(event) { + var query = event.params[1]; + this.wn.word(query, {}, function(err, word) { + if(!err && word) { + word.topExample({}, function(err, example) { + if(!err && example) { + var rep = new RegExp(query, 'g'); + event.reply(dbot.t('def', { + 'word': query + ' example', + 'definition': example.text.replace(rep, '\u00033'+query+'\u000f') + })); + } else { + event.reply(dbot.t('no_example', { 'word': query })); + } + }); + } else { + event.reply(dbot.t('no_word', { 'word': query })); + } + }); + }, + + '~rw': function(event) { + this.wn.randomWord(function(err, word) { + if(!err && word) { + this.wn.definitions(encodeURIComponent(word.word), function(err, defs) { + if(!err && defs[0]) { + event.reply(dbot.t('def', { + 'word': word.word, + 'definition': defs[0].text + })); + } else { + event.reply(dbot.t('no_def', { 'word': query })); + } + }); + } + }.bind(this)); }, '~etymology': function(event) {