diff options
| author | 8cy <[email protected]> | 2020-04-29 14:42:03 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-29 14:42:03 -0700 |
| commit | 9b2ab3b7a29983beba6908644a69925fd7adf253 (patch) | |
| tree | 2d62bbe56895bf1349b86f89d021d0ce67f6a608 /src/commands/utility/romannumeral.ts | |
| parent | formatting, blacklists, v9.0.1 (diff) | |
| download | dep-core-9b2ab3b7a29983beba6908644a69925fd7adf253.tar.xz dep-core-9b2ab3b7a29983beba6908644a69925fd7adf253.zip | |
add contact cmds, qol updates/ formatting, v9.1.0
Diffstat (limited to 'src/commands/utility/romannumeral.ts')
| -rw-r--r-- | src/commands/utility/romannumeral.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/commands/utility/romannumeral.ts b/src/commands/utility/romannumeral.ts new file mode 100644 index 0000000..8dcc331 --- /dev/null +++ b/src/commands/utility/romannumeral.ts @@ -0,0 +1,55 @@ +import { Command, CommandoMessage } from 'discord.js-commando'; +import emoji from 'emoji-random' +import romanize from 'romanize' + +module.exports = class RomanNumeralUtility extends Command { + constructor(client) { + super(client, { + name: 'romannumeral', + aliases: [ + 'roman-numeral', + 'romannumerals', + 'roman-numerals' + ], + group: 'utility', + memberName: 'romannumeral', + description: 'Converts a number to a roman numeral.', + examples: ['uwu!romannumeral 12'], + throttling: { + usages: 5, + duration: 30 + }, + userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], + clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], + args: [ + { + key: 'nNum', + prompt: 'What number would you like to translate', + type: 'integer', + min: 1 + } + ] + }); + } + run(msg: CommandoMessage, { nNum }) { + if (nNum === parseInt(nNum, 10)) { + msg.reply(romanize(nNum)) + } + + const back = value => { + let res = 0 + + const decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] + const roman = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] + for (let i = 0; i <= decimal.length; i++) { + while (value.indexOf(roman[i]) === 0) { + res += decimal[i] + value = value.replace(roman[i], '') + } + } + return res + } + + msg.reply(back(nNum) + ' ' + emoji.random()) + } +};
\ No newline at end of file |