mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Lots of Changes
This commit is contained in:
@@ -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.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user