mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
22.0.0
This commit is contained in:
@@ -15,21 +15,27 @@ module.exports = class CurrencyCommand extends Command {
|
||||
key: 'base',
|
||||
prompt: 'What currency code do you want to use as the base?',
|
||||
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.';
|
||||
validate: (base) => {
|
||||
if (codes.includes(base.toUpperCase())) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
|
||||
}
|
||||
},
|
||||
parse: base => base.toUpperCase()
|
||||
parse: (base) => base.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'to',
|
||||
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: (to) => {
|
||||
if (codes.includes(to.toUpperCase())) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
|
||||
}
|
||||
},
|
||||
parse: to => to.toUpperCase()
|
||||
parse: (to) => to.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
@@ -42,18 +48,15 @@ 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.`);
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get('http://api.fixer.io/latest')
|
||||
.query({
|
||||
base,
|
||||
symbols: to
|
||||
});
|
||||
const rate = body.rates[to];
|
||||
return msg.say(`${amount} ${base} is ${amount * rate} ${to}.`);
|
||||
} catch (err) {
|
||||
return msg.say(`${err.name}: ${err.message}`);
|
||||
if (base === to) {
|
||||
return msg.say(`Converting ${base} to ${to} is the same value, dummy.`);
|
||||
}
|
||||
const { body } = await snekfetch
|
||||
.get('http://api.fixer.io/latest')
|
||||
.query({
|
||||
base,
|
||||
symbols: to
|
||||
});
|
||||
return msg.say(`${amount} ${base} is ${amount * body.rates[to]} ${to}.`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,10 +21,10 @@ module.exports = class MathCommand extends Command {
|
||||
run(msg, args) {
|
||||
const { expression } = args;
|
||||
try {
|
||||
const solved = math.eval(expression);
|
||||
return msg.say(solved).catch(() => msg.say('Invalid Statement.'));
|
||||
const solved = math.eval(expression).toString();
|
||||
return msg.say(solved);
|
||||
} catch (err) {
|
||||
return msg.say('Invalid Statement.');
|
||||
return msg.say('Invalid Statement');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,21 +12,27 @@ module.exports = class TemperatureCommand extends Command {
|
||||
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`.';
|
||||
validate: (base) => {
|
||||
if (['celsius', 'fahrenheit', 'kelvin'].includes(base.toLowerCase())) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.';
|
||||
}
|
||||
},
|
||||
parse: base => base.toLowerCase()
|
||||
parse: (base) => base.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'to',
|
||||
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: (to) => {
|
||||
if (['celsius', 'fahrenheit', 'kelvin'].includes(to.toLowerCase())) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.';
|
||||
}
|
||||
},
|
||||
parse: to => to.toLowerCase()
|
||||
parse: (to) => to.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
@@ -39,16 +45,27 @@ module.exports = class TemperatureCommand extends Command {
|
||||
|
||||
run(msg, args) {
|
||||
const { base, to, amount } = args;
|
||||
if (base === to) return msg.say(`Converting ${base} to ${to} is the same value, dummy.`);
|
||||
if (base === to) {
|
||||
return msg.say(`Converting ${base} to ${to} is the same value, dummy.`);
|
||||
}
|
||||
if (base === 'celsius') {
|
||||
if (to === 'fahrenheit') return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`);
|
||||
if (to === 'kelvin') return msg.say(`${amount}°C is ${amount + 273.15}°K.`);
|
||||
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.`);
|
||||
if (to === 'kelvin') return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`);
|
||||
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.`);
|
||||
if (to === 'fahrenheit') return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`);
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user