decode base64

This commit is contained in:
Daniel Odendahl Jr
2018-03-12 18:38:56 +00:00
parent 3a14617543
commit ab8c828b2c
3 changed files with 20 additions and 6 deletions
+15 -3
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando');
const { base64 } = require('../../util/Util');
const { list, base64 } = require('../../util/Util');
const modes = ['encode', 'decode'];
module.exports = class Base64Command extends Command {
constructor(client) {
@@ -9,7 +10,18 @@ module.exports = class Base64Command extends Command {
group: 'text-edit',
memberName: 'base64',
description: 'Converts text to Base64.',
details: `**Modes**: ${modes.join(', ')}`,
args: [
{
key: 'mode',
prompt: `Would you like to ${list(modes, 'or')}?`,
type: 'string',
validate: mode => {
if (modes.includes(mode.toLowerCase())) return true;
return `Invalid mode, please enter either ${list(modes, 'or')}.`;
},
parse: mode => mode.toLowerCase()
},
{
key: 'text',
prompt: 'What text would you like to convert to Base64?',
@@ -23,7 +35,7 @@ module.exports = class Base64Command extends Command {
});
}
run(msg, { text }) {
return msg.say(base64(text));
run(msg, { mode, text }) {
return msg.say(base64(text, mode));
}
};