forked from GitHub/dbot
Words module api support for phrases
~define, ~example, and ~like now all support phrases.
This commit is contained in:
parent
43cfe3b637
commit
bb28cebde1
@ -4,7 +4,7 @@ var Wordnik = require('wordnik'),
|
|||||||
var words = function(dbot) {
|
var words = function(dbot) {
|
||||||
this.commands = {
|
this.commands = {
|
||||||
'~define': function(event) {
|
'~define': function(event) {
|
||||||
var query = event.params[1];
|
var query = event.params.slice(1).join(" ");
|
||||||
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(dbot.t('def', {
|
event.reply(dbot.t('def', {
|
||||||
@ -18,8 +18,8 @@ var words = function(dbot) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'~like': function(event) {
|
'~like': function(event) {
|
||||||
var query = event.params[1];
|
var query = event.params.slice(1).join(" ");
|
||||||
this.wn.word(query, {}, function(err, word) {
|
this.wn.word(encodeURIComponent(query), {}, function(err, word) {
|
||||||
if(!err && word) {
|
if(!err && word) {
|
||||||
word.related({
|
word.related({
|
||||||
'limit': 10
|
'limit': 10
|
||||||
@ -40,22 +40,18 @@ var words = function(dbot) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'~example': function(event) {
|
'~example': function(event) {
|
||||||
var query = event.params[1];
|
var query = event.params.slice(1).join(" ");
|
||||||
this.wn.word(query, {}, function(err, word) {
|
|
||||||
if(!err && word) {
|
this.wn.topExample(encodeURIComponent(query), {}, function(err, example) {
|
||||||
word.topExample({}, function(err, example) {
|
if(!err && example) {
|
||||||
if(!err && example) {
|
console.log(rep);
|
||||||
var rep = new RegExp(query, 'g');
|
var rep = new RegExp(query, 'g');
|
||||||
event.reply(dbot.t('def', {
|
event.reply(dbot.t('def', {
|
||||||
'word': query + ' example',
|
'word': query + ' example',
|
||||||
'definition': example.text.replace(rep, '\u00033'+query+'\u000f')
|
'definition': example.text.replace(rep, '\u00033'+query+'\u000f')
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
event.reply(dbot.t('no_example', { 'word': query }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('no_word', { 'word': query }));
|
event.reply(dbot.t('no_example', { 'word': query }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user