Files
xiao/commands/edit-number/roman.js
T
2020-04-09 14:37:24 -04:00

41 lines
941 B
JavaScript

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}`);
}
};