mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 08:22:22 +02:00
Updates
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { list } = require('../../util/Util');
|
||||
const codes = require('../../assets/json/currency');
|
||||
|
||||
module.exports = class CurrencyCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'currency',
|
||||
aliases: ['currency-convert', 'convert-currency'],
|
||||
group: 'number-edit',
|
||||
memberName: 'currency',
|
||||
description: 'Converts money from one currency to another.',
|
||||
details: `**Codes**: ${codes.join(', ')}`,
|
||||
args: [
|
||||
{
|
||||
key: 'base',
|
||||
prompt: `What currency code do you want to use as the base? Either ${list(codes, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: base => {
|
||||
if (codes.includes(base.toUpperCase())) return true;
|
||||
return `Invalid base, please enter either ${list(codes, 'or')}.`;
|
||||
},
|
||||
parse: base => base.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: `What currency code do you want to convert to? Either ${list(codes, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: target => {
|
||||
if (codes.includes(target.toUpperCase())) return true;
|
||||
return `Invalid target, please enter either ${list(codes, 'or')}.`;
|
||||
},
|
||||
parse: target => target.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How much money should be converted? Do not use symbols.',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { base, target, amount }) {
|
||||
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get('http://api.fixer.io/latest')
|
||||
.query({
|
||||
base,
|
||||
symbols: target
|
||||
});
|
||||
return msg.say(`${amount} ${base} is ${amount * body.rates[target]} ${target}.`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const math = require('mathjs');
|
||||
|
||||
module.exports = class MathCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'math',
|
||||
aliases: ['calculator', 'calc'],
|
||||
group: 'number-edit',
|
||||
memberName: 'math',
|
||||
description: 'Evaluates a math expression.',
|
||||
args: [
|
||||
{
|
||||
key: 'expression',
|
||||
prompt: 'What expression would you like to evaluate?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { expression }) {
|
||||
try {
|
||||
const answer = math.eval(expression).toString();
|
||||
return msg.say(answer).catch(() => msg.reply('Invalid expression.'));
|
||||
} catch (err) {
|
||||
return msg.reply('Invalid expression.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { list } = require('../../util/Util');
|
||||
const units = ['celsius', 'fahrenheit', 'kelvin'];
|
||||
|
||||
module.exports = class TemperatureCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'temperature',
|
||||
aliases: ['temperature-convert', 'convert-temperature', 'temp-convert', 'convert-temp'],
|
||||
group: 'number-edit',
|
||||
memberName: 'temperature',
|
||||
description: `Converts temperatures to/from ${list(units, 'or')}.`,
|
||||
args: [
|
||||
{
|
||||
key: 'base',
|
||||
prompt: `What temperature unit do you want to use as the base? Either ${list(units, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: base => {
|
||||
if (units.includes(base.toLowerCase())) return true;
|
||||
return `Invalid base, please enter either ${list(units, 'or')}.`;
|
||||
},
|
||||
parse: base => base.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: `What temperature unit do you want to convert to? Either ${list(units, 'or')}.`,
|
||||
type: 'string',
|
||||
validate: target => {
|
||||
if (units.includes(target.toLowerCase())) return true;
|
||||
return `Invalid target, please enter either ${list(units, 'or')}.`;
|
||||
},
|
||||
parse: target => target.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'What temperature should be converted?',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { base, target, amount }) { // eslint-disable-line consistent-return
|
||||
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