From b43be1f900adacb319fa447fda830c0f796e9dfd Mon Sep 17 00:00:00 2001 From: thoso Date: Wed, 19 Feb 2014 22:19:36 +0100 Subject: [PATCH] Adding a unit converter Due to issue #596 I coded a basic unit converter to convert time, distance, mass, volume and digital values. It depends on node-units. Also, fixed a typo. --- modules/radio/strings.json | 3 +-- modules/units/README.md | 24 ++++++++++++++++++++++++ modules/units/strings.json | 8 ++++++++ modules/units/units.js | 33 +++++++++++++++++++++++++++++++++ modules/units/usage.json | 3 +++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 modules/units/README.md create mode 100644 modules/units/strings.json create mode 100644 modules/units/units.js create mode 100644 modules/units/usage.json diff --git a/modules/radio/strings.json b/modules/radio/strings.json index 8a4c771..d4c07ad 100644 --- a/modules/radio/strings.json +++ b/modules/radio/strings.json @@ -4,8 +4,7 @@ }, "now_playing": { "en": "Now Playing: {name} - {song} - {url}" - } - + }, "request":{ "en":"{dj}: User {user} requests '{song}' to be played on tripradio." } diff --git a/modules/units/README.md b/modules/units/README.md new file mode 100644 index 0000000..9d59619 --- /dev/null +++ b/modules/units/README.md @@ -0,0 +1,24 @@ +## Unit conversion + +Converts units into other units. + +### Description + +This module provides a command which allows users to convert units into another +unit given the international character of networks. Converts time, distance, +mass, volume and digital values. + +It has following dependencies: +node-units : https://github.com/brettlangdon/node-units + +### Commands + +#### ~convert [input value] [input unit] to [output unit] + +Example: +~convert 5 minutes to s +~convert 20 quarts to gallons + +### TODO + +Currency Conversion \ No newline at end of file diff --git a/modules/units/strings.json b/modules/units/strings.json new file mode 100644 index 0000000..35237f7 --- /dev/null +++ b/modules/units/strings.json @@ -0,0 +1,8 @@ +{ + "result": { + "en": "{input}: {output}" + }, + "error": { + "en": "Something went wrong :( Example:'~convert 5 minutes to s'" + } +} diff --git a/modules/units/units.js b/modules/units/units.js new file mode 100644 index 0000000..cda7d36 --- /dev/null +++ b/modules/units/units.js @@ -0,0 +1,33 @@ +/** + * 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) { + this.commands = { + '~convert': function(event) { + var query = event.input[1]; + try { + event.reply(dbot.t('result', { + 'input': query, + 'output': result + })); + var result = unit.convert(query); + } + } catch (e) { + event.reply(dbot.t('error')); + } + + } + }; + +}; + +exports.fetch = function(dbot) { + return new units(dbot); +}; diff --git a/modules/units/usage.json b/modules/units/usage.json new file mode 100644 index 0000000..b7ce8cf --- /dev/null +++ b/modules/units/usage.json @@ -0,0 +1,3 @@ +{ + "~convert": "~convert [input value] [input unit] to [output unit]" +} \ No newline at end of file