2014-02-19 22:19:36 +01:00
|
|
|
/**
|
|
|
|
* Module Name: Unit Conversion
|
|
|
|
* Description: Converts units.
|
|
|
|
* Requires: node-units [https://github.com/brettlangdon/node-units]
|
|
|
|
* TODO: currency converting
|
|
|
|
*/
|
|
|
|
|
|
|
|
var _ = require('underscore')._,
|
|
|
|
unit = require('node-units');
|
|
|
|
|
|
|
|
var units = function(dbot) {
|
2014-02-20 21:10:45 +01:00
|
|
|
this.commands = {
|
|
|
|
'~convert': function(event) {
|
2014-02-19 22:19:36 +01:00
|
|
|
var query = event.input[1];
|
|
|
|
try {
|
2014-02-20 20:25:50 +01:00
|
|
|
var result = unit.convert(query);
|
2014-02-20 21:10:45 +01:00
|
|
|
event.reply(dbot.t('unit_result', {
|
2014-02-19 22:19:36 +01:00
|
|
|
'input': query,
|
|
|
|
'output': result
|
|
|
|
}));
|
|
|
|
}
|
2014-02-20 21:10:45 +01:00
|
|
|
catch (e) {
|
|
|
|
event.reply(dbot.t('unit_error'));
|
|
|
|
}
|
2014-02-19 22:19:36 +01:00
|
|
|
}
|
2014-02-20 21:10:45 +01:00
|
|
|
};
|
|
|
|
this.commands['~convert'].regex = [/^convert ([\d\w\s-]*)/, 2];
|
2014-02-19 22:19:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new units(dbot);
|
|
|
|
};
|