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));
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "68.0.0",
"version": "69.0.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+4 -2
View File
@@ -54,8 +54,10 @@ class Util {
return arr;
}
static base64(text) {
return Buffer.from(text).toString('base64');
static base64(text, mode = 'encode') {
if (mode === 'encode') return Buffer.from(text).toString('base64');
if (mode === 'decode') return Buffer.from(text, 'base64').toString('utf8');
throw new TypeError(`${mode} is not a supported base64 mode.`);
}
static hash(text, algorithm) {