Currency Converter

This commit is contained in:
Daniel Odendahl Jr
2017-05-05 13:59:41 +00:00
parent 6eec8039cb
commit d76835eaec
3 changed files with 91 additions and 1 deletions
+57
View File
@@ -0,0 +1,57 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
const codes = require('./codes');
module.exports = class CurrencyCommand extends Command {
constructor(client) {
super(client, {
name: 'currency',
group: 'random',
memberName: 'currentUser',
description: 'Converts from one currency to another.',
details: `**Codes:** ${codes.join(', ')}`,
args: [
{
key: 'base',
prompt: 'What currency code do you want to use as the base?',
type: 'string',
validate: base => {
if(codes[base.toUpperCase()])
return true;
return `${base} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
},
parse: base => base.toUpperCase()
},
{
key: 'to',
prompt: 'What currency code do you want to convert to?',
type: 'string',
validate: to => {
if(codes[to.toUpperCase()])
return true;
return `${to} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
},
parse: code => code.toUpperCase()
},
{
key: 'amount',
prompt: 'How much money should be converted? Do not use symbols.',
type: 'integer'
}
]
});
}
async run(msg, args) {
const { base, to, amount } = args;
try {
const { body } = await request
.get(`http://api.fixer.io/latest?base=${base}`);
const rate = body[to];
const converted = rate * amount;
return msg.say(`${amount} ${base} is ${converted} ${to}.`);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
}
}
};
+33
View File
@@ -0,0 +1,33 @@
[
"AUD",
"BGN",
"BRL",
"CAD",
"CHF",
"CNY",
"CZK",
"DKK",
"GBP",
"HKD",
"HRK",
"HUF",
"IDR",
"ILS",
"INR",
"JPY",
"KRW",
"MXN",
"MYR",
"NOK",
"NZD",
"PHP",
"PLN",
"RON",
"RUB",
"SEK",
"SGD",
"THB",
"TRY",
"ZAR",
"EUR"
]
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "18.1.1",
"version": "18.2.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {