Some music fixes, merge decode and encode into a single command

This commit is contained in:
Essem 2022-04-10 11:20:52 -05:00
parent c37a8a5fcf
commit dd7bd6b4cc
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
9 changed files with 55 additions and 38 deletions

View file

@ -0,0 +1,46 @@
import Command from "../../classes/command.js";
import { clean } from "../../utils/misc.js";
class Base64Command extends Command {
async run() {
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!";
const string = this.type === "classic" ? this.args.slice(1).join(" ") : this.options.text;
if (!string || !string.trim()) return `You need to provide a string to ${command}!`;
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;

View file

@ -1,16 +0,0 @@
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
class DecodeCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide a string to decode!";
const b64Decoded = Buffer.from(this.args.join(" "), "base64").toString("utf8");
return `\`\`\`\n${await clean(b64Decoded)}\`\`\``;
}
static description = "Decodes a Base64 string";
static aliases = ["b64decode", "base64decode"];
static arguments = ["[text]"];
}
export default DecodeCommand;

View file

@ -1,15 +0,0 @@
import Command from "../../classes/command.js";
class EncodeCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide a string to encode!";
const b64Encoded = Buffer.from(this.args.join(" "), "utf8").toString("base64");
return `\`\`\`\n${b64Encoded}\`\`\``;
}
static description = "Encodes a Base64 string";
static aliases = ["b64encode", "base64encode"];
static arguments = ["[text]"];
}
export default EncodeCommand;