3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

etymology

This commit is contained in:
reality 2014-11-28 14:43:16 +00:00
parent f7fbbc7bd0
commit 1a144c6459
2 changed files with 20 additions and 7 deletions

View File

@ -13,5 +13,8 @@
},
"no_similar": {
"en": "No related words found for {word}"
},
"origin": {
"en": "{word} origin: {origin}"
}
}

View File

@ -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 }));
}
});
},