mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 10:02:05 +02:00
More uniform group names
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { formatNumber } = require('../../util/Util');
|
||||
|
||||
module.exports = class CurrencyCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'currency',
|
||||
group: 'edit-number',
|
||||
memberName: 'currency',
|
||||
description: 'Converts currency from one currency to another.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Foreign exchange rates API',
|
||||
url: 'https://exchangeratesapi.io/',
|
||||
reason: 'API'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How much currency should be converted? Do not use symbols.',
|
||||
type: 'float'
|
||||
},
|
||||
{
|
||||
key: 'base',
|
||||
prompt: 'What currency code (e.g. USD) do you want to use as the base?',
|
||||
type: 'string',
|
||||
min: 3,
|
||||
max: 3,
|
||||
parse: base => base.toUpperCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: 'What currency code (e.g. USD) do you want to convert to?',
|
||||
type: 'string',
|
||||
min: 3,
|
||||
max: 3,
|
||||
parse: target => target.toUpperCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.rates = new Map();
|
||||
}
|
||||
|
||||
async run(msg, { base, target, amount }) {
|
||||
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
|
||||
try {
|
||||
const rate = await this.fetchRate(base, target);
|
||||
return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(amount * rate)} ${target}.`);
|
||||
} catch (err) {
|
||||
if (err.status === 400) return msg.say('Invalid base/target.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async fetchRate(base, target) {
|
||||
const query = `${base}-${target}`;
|
||||
if (this.rates.has(query)) return this.rates.get(query);
|
||||
const { body } = await request
|
||||
.get('https://api.exchangeratesapi.io/latest')
|
||||
.query({
|
||||
base,
|
||||
symbols: target
|
||||
});
|
||||
this.rates.set(query, body.rates[target]);
|
||||
setTimeout(() => this.rates.delete(query), 1.8e+6);
|
||||
return body.rates[target];
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { above100, above92, above88, above80, below80 } = require('../../assets/json/final-grade');
|
||||
|
||||
module.exports = class FinalGradeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'final-grade',
|
||||
aliases: ['final-grade-calculator', 'final-grade-calc'],
|
||||
group: 'edit-number',
|
||||
memberName: 'final-grade',
|
||||
description: 'Determines the grade you need to make on your final to get your desired course grade.',
|
||||
credit: [
|
||||
{
|
||||
name: 'RogerHub Final Grade Calculator',
|
||||
url: 'https://rogerhub.com/final-grade-calculator/',
|
||||
reason: 'Concept, Code'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'current',
|
||||
label: 'current grade',
|
||||
prompt: 'What is your current grade in the class?',
|
||||
type: 'integer',
|
||||
min: 0
|
||||
},
|
||||
{
|
||||
key: 'desired',
|
||||
label: 'desired grade',
|
||||
prompt: 'What is the minimum grade you want in the class?',
|
||||
type: 'integer',
|
||||
min: 0
|
||||
},
|
||||
{
|
||||
key: 'weight',
|
||||
prompt: 'What percentage of your grade is the final worth?',
|
||||
type: 'integer',
|
||||
max: 100,
|
||||
min: 0
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { current, desired, weight }) {
|
||||
const required = Math.round((((desired / 100) - ((current / 100) * (1 - (weight / 100)))) / (weight / 100)) * 100);
|
||||
const diff = desired - current;
|
||||
let text;
|
||||
if (required > 100) text = above100[Math.floor(Math.random() * above100.length)];
|
||||
else if (required > 92 || diff > weight * 0.3) text = above92[Math.floor(Math.random() * above92.length)];
|
||||
else if (required > 88 || diff > 0) text = above88[Math.floor(Math.random() * above88.length)];
|
||||
else if (required > 80 || diff > weight * -0.3) text = above80[Math.floor(Math.random() * above80.length)];
|
||||
else text = below80[Math.floor(Math.random() * below80.length)];
|
||||
return msg.say(`You will need to score at least ${required}% on your final to get a ${desired}% overall. ${text}`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class GradeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'grade',
|
||||
aliases: ['grade-calculator', 'grade-calc'],
|
||||
group: 'edit-number',
|
||||
memberName: 'grade',
|
||||
description: 'Determines your grade on an assignment on an 100-point scale.',
|
||||
args: [
|
||||
{
|
||||
key: 'earned',
|
||||
label: 'points earned',
|
||||
prompt: 'How many points did you get?',
|
||||
type: 'integer',
|
||||
min: 0
|
||||
},
|
||||
{
|
||||
key: 'total',
|
||||
label: 'total points',
|
||||
prompt: 'How many points are available to recieve?',
|
||||
type: 'integer',
|
||||
min: 0
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { earned, total }) {
|
||||
const score = Math.round((earned / total) * 100);
|
||||
return msg.reply(`Your score is a **${score}%**${score >= 70 ? '! Nice job!' : '... Too bad...'}`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { list, firstUpperCase, formatNumber } = require('../../util/Util');
|
||||
const planets = require('../../assets/json/gravity');
|
||||
|
||||
module.exports = class GravityCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'gravity',
|
||||
group: 'edit-number',
|
||||
memberName: 'gravity',
|
||||
description: 'Determines weight on another planet.',
|
||||
details: `**Planets:** ${Object.keys(planets).join(', ')}`,
|
||||
credit: [
|
||||
{
|
||||
name: 'NASA',
|
||||
url: 'https://www.nasa.gov/',
|
||||
reason: 'Planet Gravity Data',
|
||||
reasonURL: 'https://nssdc.gsfc.nasa.gov/planetary/factsheet/planet_table_ratio.html'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'weight',
|
||||
prompt: 'What should the starting weight be (in KG)?',
|
||||
type: 'float'
|
||||
},
|
||||
{
|
||||
key: 'planet',
|
||||
prompt: `What planet do you want to use as the base? Either ${list(Object.keys(planets), 'or')}.`,
|
||||
type: 'string',
|
||||
oneOf: Object.keys(planets),
|
||||
parse: planet => planet.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { weight, planet }) {
|
||||
const result = weight * planets[planet];
|
||||
return msg.say(`${formatNumber(weight)} kg on ${firstUpperCase(planet)} is ${formatNumber(result)} kg.`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const math = require('mathjs');
|
||||
|
||||
module.exports = class MathCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'math',
|
||||
aliases: ['mathematics', 'solve'],
|
||||
group: 'edit-number',
|
||||
memberName: 'math',
|
||||
description: 'Evaluates a math expression.',
|
||||
credit: [
|
||||
{
|
||||
name: 'mathjs',
|
||||
url: 'https://mathjs.org/',
|
||||
reason: 'Expression Parser'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'expression',
|
||||
prompt: 'What expression do you want to evaluate?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { expression }) {
|
||||
try {
|
||||
const evaluated = math.evaluate(expression).toString();
|
||||
return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.'));
|
||||
} catch {
|
||||
return msg.reply('Invalid expression.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { formatNumber } = require('../../util/Util');
|
||||
|
||||
module.exports = class PrimeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'prime',
|
||||
aliases: ['is-prime'],
|
||||
group: 'edit-number',
|
||||
memberName: 'prime',
|
||||
description: 'Determines if a number is a prime number.',
|
||||
args: [
|
||||
{
|
||||
key: 'number',
|
||||
prompt: 'What number do you want to check?',
|
||||
type: 'integer',
|
||||
max: Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { number }) {
|
||||
return msg.reply(`${formatNumber(number)} is${this.isPrime(number) ? '' : ' not'} a prime number.`);
|
||||
}
|
||||
|
||||
isPrime(number) {
|
||||
if (number < 2) return false;
|
||||
for (let i = 2; i < number; i++) {
|
||||
if (number % i === 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const numerals = require('../../assets/json/roman');
|
||||
|
||||
module.exports = class RomanCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'roman',
|
||||
aliases: ['roman-numeral'],
|
||||
group: 'edit-number',
|
||||
memberName: 'roman',
|
||||
description: 'Converts a number to roman numerals.',
|
||||
args: [
|
||||
{
|
||||
key: 'number',
|
||||
prompt: 'What number would you like to convert to roman numerals?',
|
||||
type: 'integer',
|
||||
min: -3999999,
|
||||
max: 3999999
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { number }) {
|
||||
if (number === 0) return msg.reply('_nulla_');
|
||||
let negative = false;
|
||||
if (number < 0) {
|
||||
negative = true;
|
||||
number = Math.abs(number);
|
||||
}
|
||||
let result = '';
|
||||
for (const [numeral, value] of Object.entries(numerals)) {
|
||||
while (number >= value) {
|
||||
result += numeral;
|
||||
number -= value;
|
||||
}
|
||||
}
|
||||
return msg.reply(`${negative ? '-' : ''}${result}`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class ScientificNotationCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'scientific-notation',
|
||||
aliases: ['science-notation', 'exponential-notation'],
|
||||
group: 'edit-number',
|
||||
memberName: 'scientific-notation',
|
||||
description: 'Converts a number to scientific notation.',
|
||||
args: [
|
||||
{
|
||||
key: 'number',
|
||||
prompt: 'What number do you want to convert to scientific notation?',
|
||||
type: 'float'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { number }) {
|
||||
return msg.reply(number.toExponential());
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const math = require('mathjs');
|
||||
const { formatNumber } = require('../../util/Util');
|
||||
|
||||
module.exports = class UnitsCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'units',
|
||||
aliases: ['convert'],
|
||||
group: 'edit-number',
|
||||
memberName: 'units',
|
||||
description: 'Converts units to/from other units.',
|
||||
credit: [
|
||||
{
|
||||
name: 'mathjs',
|
||||
url: 'https://mathjs.org/',
|
||||
reason: 'Expression Parser'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'amount',
|
||||
prompt: 'How many units should be converted?',
|
||||
type: 'float'
|
||||
},
|
||||
{
|
||||
key: 'base',
|
||||
prompt: 'What unit type do you want to convert from?',
|
||||
type: 'string',
|
||||
parse: base => base.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
prompt: 'What unit type do you want to convert to?',
|
||||
type: 'string',
|
||||
parse: target => target.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { base, target, amount }) {
|
||||
try {
|
||||
const value = math.unit(amount, base).toNumber(target);
|
||||
return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(value)} ${target}.`);
|
||||
} catch {
|
||||
return msg.say('Either an invalid unit type was provided or the unit types do not match.');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user