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

33 lines
903 B
JavaScript
Raw Normal View History

/**
* 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) {
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', {
'input': query,
'output': result
}));
}
2014-02-20 21:10:45 +01:00
catch (e) {
event.reply(dbot.t('unit_error'));
}
}
2014-02-20 21:10:45 +01:00
};
this.commands['~convert'].regex = [/^convert ([\d\w\s-]*)/, 2];
};
exports.fetch = function(dbot) {
return new units(dbot);
};