mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
decode base64
This commit is contained in:
@@ -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
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user