2014-11-28 15:43:16 +01:00
|
|
|
var Wordnik = require('wordnik'),
|
|
|
|
parseString = require('xml2js').parseString;
|
2013-06-11 19:24:42 +02:00
|
|
|
|
|
|
|
var words = function(dbot) {
|
|
|
|
this.commands = {
|
|
|
|
'~define': function(event) {
|
2018-03-30 18:22:03 +02:00
|
|
|
var query = event.params.slice(1).join(" ");
|
2013-07-28 23:26:04 +02:00
|
|
|
this.wn.definitions(encodeURIComponent(query), function(err, defs) {
|
2013-06-11 19:24:42 +02:00
|
|
|
if(!err && defs[0]) {
|
2014-10-31 18:02:17 +01:00
|
|
|
event.reply(dbot.t('def', {
|
|
|
|
'word': query,
|
|
|
|
'definition': defs[0].text
|
|
|
|
}));
|
2013-06-11 19:24:42 +02:00
|
|
|
} else {
|
2014-10-31 18:02:17 +01:00
|
|
|
event.reply(dbot.t('no_def', { 'word': query }));
|
2013-06-11 19:24:42 +02:00
|
|
|
}
|
|
|
|
});
|
2013-07-08 13:02:27 +02:00
|
|
|
},
|
2013-12-27 17:24:16 +01:00
|
|
|
|
2014-10-31 05:19:05 +01:00
|
|
|
'~like': function(event) {
|
2018-03-30 18:22:03 +02:00
|
|
|
var query = event.params.slice(1).join(" ");
|
|
|
|
this.wn.word(encodeURIComponent(query), {}, function(err, word) {
|
2014-10-31 05:27:08 +01:00
|
|
|
if(!err && word) {
|
2014-10-31 05:19:05 +01:00
|
|
|
word.related({
|
|
|
|
'limit': 10
|
|
|
|
}, function(err, related) {
|
2014-10-31 05:27:08 +01:00
|
|
|
if(related[0]) {
|
2014-10-31 18:02:17 +01:00
|
|
|
event.reply(dbot.t('def', {
|
|
|
|
'word': 'Words related to ' + query,
|
|
|
|
'definition': related[0].words.join(', ') + '.'
|
|
|
|
}));
|
2014-10-31 05:27:08 +01:00
|
|
|
} else {
|
2014-10-31 18:02:17 +01:00
|
|
|
event.reply(dbot.t('no_similar', { 'word': query }));
|
2014-10-31 05:27:08 +01:00
|
|
|
}
|
2014-10-31 05:19:05 +01:00
|
|
|
});
|
2014-10-31 05:21:33 +01:00
|
|
|
} else {
|
2014-10-31 18:02:17 +01:00
|
|
|
event.reply(dbot.t('no_word', { 'word': query }));
|
2014-10-31 05:19:05 +01:00
|
|
|
}
|
|
|
|
});
|
2014-10-31 18:02:17 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~example': function(event) {
|
2018-03-30 18:22:03 +02:00
|
|
|
var query = event.params.slice(1).join(" ");
|
|
|
|
|
|
|
|
this.wn.topExample(encodeURIComponent(query), {}, function(err, example) {
|
|
|
|
if(!err && example) {
|
|
|
|
console.log(rep);
|
|
|
|
var rep = new RegExp(query, 'g');
|
|
|
|
event.reply(dbot.t('def', {
|
|
|
|
'word': query + ' example',
|
|
|
|
'definition': example.text.replace(rep, '\u00033'+query+'\u000f')
|
|
|
|
}));
|
2014-10-31 18:02:17 +01:00
|
|
|
} else {
|
2018-03-30 18:22:03 +02:00
|
|
|
event.reply(dbot.t('no_example', { 'word': query }));
|
2014-10-31 18:02:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
'~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]) {
|
2014-11-30 05:01:14 +01:00
|
|
|
if(!defs[0].text.match(/plural/i) && !defs[0].text.match(/participle/i)) {
|
2014-11-29 06:02:11 +01:00
|
|
|
event.reply(dbot.t('def', {
|
|
|
|
'word': word.word,
|
|
|
|
'definition': defs[0].text
|
|
|
|
}));
|
|
|
|
} else {
|
2014-11-30 04:58:22 +01:00
|
|
|
dbot.commands['rw'](event);
|
2014-11-29 06:02:11 +01:00
|
|
|
}
|
2014-10-31 18:02:17 +01:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('no_def', { 'word': query }));
|
|
|
|
}
|
2014-11-30 04:57:41 +01:00
|
|
|
}.bind(this));
|
2014-10-31 18:02:17 +01:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2014-10-31 05:19:05 +01:00
|
|
|
},
|
|
|
|
|
2013-12-27 17:24:16 +01:00
|
|
|
'~etymology': function(event) {
|
|
|
|
var query = event.params[1];
|
2014-11-28 15:43:16 +01:00
|
|
|
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 }));
|
|
|
|
}
|
|
|
|
});
|
2013-12-27 17:24:16 +01:00
|
|
|
} else {
|
2014-11-28 15:43:16 +01:00
|
|
|
event.reply(dbot.t('no_word', { 'word': query }));
|
2013-12-27 17:24:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-07-08 13:02:27 +02:00
|
|
|
|
|
|
|
'~jimble': function(event) {
|
|
|
|
event.reply(event.params[1].split('').sort(function() {
|
|
|
|
return (Math.round(Math.random()) - 0.5);
|
|
|
|
}).join(''));
|
2015-05-01 09:58:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~merge': function(event) {
|
|
|
|
var a = event.params[1]; var b = event.params[2]; event.reply(a.slice(0,_.random(1,a.length)) + b.slice(_.random(b.length-1)));
|
|
|
|
}
|
2013-06-11 19:24:42 +02:00
|
|
|
};
|
2013-12-29 19:38:24 +01:00
|
|
|
this.commands['~jimble'].regex = [/^jimble (.+)$/, 2];
|
2013-06-11 19:24:42 +02:00
|
|
|
|
2015-03-24 20:17:54 +01:00
|
|
|
this.listener = function(event) {
|
2015-03-24 20:30:46 +01:00
|
|
|
var matchOne = event.message.match(new RegExp(dbot.config.name + ': should (\\w+) (.+) or (.*)\\?', 'i'));
|
2015-03-24 20:57:49 +01:00
|
|
|
var matchTwo = event.message.match(new RegExp(dbot.config.name + ': should (\\w+) (.+)\\?', 'i'));
|
2015-03-24 20:17:54 +01:00
|
|
|
if(matchOne) {
|
2015-03-24 20:33:06 +01:00
|
|
|
var pre = matchOne[1];
|
2015-03-24 20:17:54 +01:00
|
|
|
if(pre == 'i' || pre == 'I') {
|
|
|
|
pre = 'You';
|
|
|
|
}
|
|
|
|
|
2015-03-24 20:34:12 +01:00
|
|
|
if(Math.floor(Math.random() * (6)) == 1) {
|
2015-03-24 20:39:09 +01:00
|
|
|
dbot.api.quotes.getInterpolatedQuote(event.server, event.channel.name, event.user, 'should_responses', function(q) {
|
2015-03-24 20:17:54 +01:00
|
|
|
event.reply(pre + ' should ' + q);
|
|
|
|
});
|
|
|
|
} else {
|
2015-03-24 20:32:19 +01:00
|
|
|
event.reply(pre + ' should ' + matchOne[_.random(2, 3)].replace(/,/,'').replace(/should/,''));
|
2015-03-24 20:17:54 +01:00
|
|
|
}
|
2015-03-24 20:57:49 +01:00
|
|
|
} else if(matchTwo) { // I know i can do it in the one regex shut up
|
|
|
|
var pre = matchTwo[1];
|
|
|
|
if(pre == 'i' || pre == 'I') {
|
|
|
|
pre = 'You';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Math.floor(Math.random() * (6)) == 1) {
|
|
|
|
dbot.api.quotes.getInterpolatedQuote(event.server, event.channel.name, event.user, 'should_responses', function(q) {
|
|
|
|
event.reply(pre + ' should ' + q);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var choice = [ '', 'not '];
|
|
|
|
event.reply(pre + ' should ' + choice[_.random(0, 1)] + matchTwo[2].replace(/,/,'').replace(/should/,''));
|
|
|
|
}
|
2015-03-24 20:17:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this.on = 'PRIVMSG';
|
|
|
|
|
2013-06-11 19:24:42 +02:00
|
|
|
this.onLoad = function() {
|
|
|
|
this.wn = new Wordnik({
|
|
|
|
'api_key': this.config.api_key
|
|
|
|
});
|
|
|
|
}.bind(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new words(dbot);
|
|
|
|
};
|