Lots of Changes

This commit is contained in:
Daniel Odendahl Jr
2017-08-26 01:20:43 +00:00
parent d2008c749d
commit 56e72f7509
78 changed files with 393 additions and 389 deletions
+11 -10
View File
@@ -1,5 +1,6 @@
const Command = require('../../structures/Command');
const snekfetch = require('snekfetch');
const { list } = require('../../structures/Util');
const codes = require('../../assets/json/currency');
module.exports = class CurrencyCommand extends Command {
@@ -17,19 +18,19 @@ module.exports = class CurrencyCommand extends Command {
type: 'string',
validate: base => {
if (codes.includes(base.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
return `Invalid base, please enter either ${list(codes, 'or')}.`;
},
parse: base => base.toUpperCase()
},
{
key: 'to',
key: 'target',
prompt: 'What currency code do you want to convert to?',
type: 'string',
validate: to => {
if (codes.includes(to.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
validate: target => {
if (codes.includes(target.toUpperCase())) return true;
return `Invalid target, please enter either ${list(codes, 'or')}.`;
},
parse: to => to.toUpperCase()
parse: target => target.toUpperCase()
},
{
key: 'amount',
@@ -41,14 +42,14 @@ module.exports = class CurrencyCommand extends Command {
}
async run(msg, args) {
const { base, to, amount } = args;
if (base === to) return msg.say(`Converting ${base} to ${to} is the same value, dummy.`);
const { base, target, amount } = args;
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
const { body } = await snekfetch
.get('http://api.fixer.io/latest')
.query({
base,
symbols: to
symbols: target
});
return msg.say(`${amount} ${base} is ${amount * body.rates[to]} ${to}.`);
return msg.say(`${amount} ${base} is ${amount * body.rates[target]} ${target}.`);
}
};
+23 -20
View File
@@ -1,4 +1,6 @@
const Command = require('../../structures/Command');
const { list } = require('../../structures/Util');
const units = ['celsius', 'fahrenheit', 'kelvin'];
module.exports = class TemperatureCommand extends Command {
constructor(client) {
@@ -6,27 +8,27 @@ module.exports = class TemperatureCommand extends Command {
name: 'temperature',
group: 'num-edit',
memberName: 'temperature',
description: 'Converts temperatures to/from Celsius, Fahrenheit, or Kelvin.',
description: `Converts temperatures to/from ${list(units, 'or')}.`,
args: [
{
key: 'base',
prompt: 'What temperature unit do you want to use as the base?',
type: 'string',
validate: base => {
if (['celsius', 'fahrenheit', 'kelvin'].includes(base.toLowerCase())) return true;
return 'Please enter either celsius, fahrenheit, or kelvin.';
if (units.includes(base.toLowerCase())) return true;
return `Invalid base, please enter either ${list(units, 'or')}.`;
},
parse: base => base.toLowerCase()
},
{
key: 'to',
key: 'target',
prompt: 'What temperature unit do you want to convert to?',
type: 'string',
validate: to => {
if (['celsius', 'fahrenheit', 'kelvin'].includes(to.toLowerCase())) return true;
return 'Please enter either celsius, fahrenheit, or kelvin.';
validate: target => {
if (units.includes(target.toLowerCase())) return true;
return `Invalid target, please enter either ${list(units, 'or')}.`;
},
parse: to => to.toLowerCase()
parse: target => target.toLowerCase()
},
{
key: 'amount',
@@ -38,18 +40,19 @@ module.exports = class TemperatureCommand extends Command {
}
run(msg, args) { // eslint-disable-line consistent-return
const { base, to, amount } = args;
if (base === to) {
return msg.say(`Converting ${base} to ${to} is the same value, dummy.`);
} else if (base === 'celsius') {
if (to === 'fahrenheit') return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`);
else if (to === 'kelvin') return msg.say(`${amount}°C is ${amount + 273.15}°K.`);
} else if (base === 'fahrenheit') {
if (to === 'celsius') return msg.say(`${amount}°F is ${(amount - 32) / 1.8}°C.`);
else if (to === 'kelvin') return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`);
} else if (base === 'kelvin') {
if (to === 'celsius') return msg.say(`${amount}°K is ${amount - 273.15}°C.`);
else if (to === 'fahrenheit') return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`);
const { base, target, amount } = args;
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
if (base === 'celsius') {
if (target === 'fahrenheit') return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`);
if (target === 'kelvin') return msg.say(`${amount}°C is ${amount + 273.15}°K.`);
}
if (base === 'fahrenheit') {
if (target === 'celsius') return msg.say(`${amount}°F is ${(amount - 32) / 1.8}°C.`);
if (target === 'kelvin') return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`);
}
if (base === 'kelvin') {
if (target === 'celsius') return msg.say(`${amount}°K is ${amount - 273.15}°C.`);
if (target === 'fahrenheit') return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`);
}
}
};