From 1a144c6459d74471c613237a44cb0d317f7d0d83 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 28 Nov 2014 14:43:16 +0000 Subject: [PATCH] etymology --- modules/words/strings.json | 3 +++ modules/words/words.js | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/modules/words/strings.json b/modules/words/strings.json index 1bf7b97..0eb7231 100644 --- a/modules/words/strings.json +++ b/modules/words/strings.json @@ -13,5 +13,8 @@ }, "no_similar": { "en": "No related words found for {word}" + }, + "origin": { + "en": "{word} origin: {origin}" } } diff --git a/modules/words/words.js b/modules/words/words.js index f616316..06c89a8 100644 --- a/modules/words/words.js +++ b/modules/words/words.js @@ -1,4 +1,5 @@ -var Wordnik = require('wordnik'); +var Wordnik = require('wordnik'), + parseString = require('xml2js').parseString; var words = function(dbot) { this.commands = { @@ -78,13 +79,22 @@ var words = function(dbot) { '~etymology': function(event) { var query = event.params[1]; - this.wn.etymologies(encodeURIComponent(query), { - 'format': 'json' - }, function(err, defs) { - if(!err && defs[0]) { - event.reply(query + ' etymology: ' + defs[0]); + this.wn.word(query, {}, function(err, word) { + if(!err && word) { + word.etymologies({},function(err, origin) { + if(!err && origin[0]) { + parseString(origin[0], function(err, string) { + event.reply(dbot.t('origin', { + 'word': query, + 'origin': string.ety._ + })); + }); + } else { + event.reply(dbot.t('no_def', { 'word': query })); + } + }); } else { - event.reply('No etymology found for ' + query); + event.reply(dbot.t('no_word', { 'word': query })); } }); },