3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 04:32:37 +01:00

Words updates

This commit is contained in:
reality 2014-10-31 17:02:17 +00:00
parent 1b67b04630
commit bdbd5ee8e4
3 changed files with 69 additions and 9 deletions

View File

@ -1,3 +1,4 @@
{ {
"api_key": "http://developer.wordnik.com/" "api_key": "http://developer.wordnik.com/",
"outputPrefix": "\u000311words\u000f"
} }

View File

@ -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}"
}
}

View File

@ -6,9 +6,12 @@ var words = function(dbot) {
var query = event.params[1]; var query = event.params[1];
this.wn.definitions(encodeURIComponent(query), function(err, defs) { this.wn.definitions(encodeURIComponent(query), function(err, defs) {
if(!err && defs[0]) { if(!err && defs[0]) {
event.reply(query + ': ' + defs[0].text); event.reply(dbot.t('def', {
'word': query,
'definition': defs[0].text
}));
} else { } 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 'limit': 10
}, function(err, related) { }, function(err, related) {
if(related[0]) { if(related[0]) {
event.reply('Words related to ' + query + ': ' + event.reply(dbot.t('def', {
related[0].words.join(', ') + '.'); 'word': 'Words related to ' + query,
'definition': related[0].words.join(', ') + '.'
}));
} else { } else {
event.reply('No similar words found.'); event.reply(dbot.t('no_similar', { 'word': query }));
} }
}); });
} else { } 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) { '~etymology': function(event) {