2022-04-10 16:20:52 +00:00
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
import { clean } from "../../utils/misc.js";
|
|
|
|
|
|
|
|
class Base64Command extends Command {
|
|
|
|
async run() {
|
2022-09-01 01:00:34 +00:00
|
|
|
this.success = false;
|
2022-04-10 16:20:52 +00:00
|
|
|
if (this.type === "classic" && this.args.length === 0) return "You need to provide whether you want to encode or decode the text!";
|
|
|
|
const command = this.type === "classic" ? this.args[0].toLowerCase() : this.optionsArray[0].name.toLowerCase();
|
|
|
|
if (command !== "decode" && command !== "encode") return "You need to provide whether you want to encode or decode the text!";
|
2022-06-07 23:26:40 +00:00
|
|
|
const string = this.options.text ?? this.args.slice(1).join(" ");
|
2022-04-10 16:20:52 +00:00
|
|
|
if (!string || !string.trim()) return `You need to provide a string to ${command}!`;
|
2022-09-01 01:00:34 +00:00
|
|
|
this.success = true;
|
2022-04-10 16:20:52 +00:00
|
|
|
if (command === "decode") {
|
|
|
|
const b64Decoded = Buffer.from(string, "base64").toString("utf8");
|
|
|
|
return `\`\`\`\n${await clean(b64Decoded)}\`\`\``;
|
|
|
|
} else if (command === "encode") {
|
|
|
|
const b64Encoded = Buffer.from(string, "utf8").toString("base64");
|
|
|
|
return `\`\`\`\n${b64Encoded}\`\`\``;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static flags = [{
|
|
|
|
name: "decode",
|
|
|
|
type: 1,
|
|
|
|
description: "Decodes a Base64 string",
|
|
|
|
options: [{
|
|
|
|
name: "text",
|
|
|
|
type: 3,
|
|
|
|
description: "The text to decode",
|
|
|
|
required: true
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
name: "encode",
|
|
|
|
type: 1,
|
|
|
|
description: "Encodes a Base64 string",
|
|
|
|
options: [{
|
|
|
|
name: "text",
|
|
|
|
type: 3,
|
|
|
|
description: "The text to encode",
|
|
|
|
required: true
|
|
|
|
}]
|
|
|
|
}];
|
|
|
|
|
|
|
|
static description = "Encodes/decodes a Base64 string";
|
|
|
|
static arguments = ["[encode/decode]", "[text]"];
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Base64Command;
|