Remove delay parameter, change argument handling, make help command show proper flag types

This commit is contained in:
Essem 2022-06-07 18:26:40 -05:00
parent 28f0245652
commit 6b34cb9d9e
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
63 changed files with 82 additions and 219 deletions

View file

@ -6,7 +6,7 @@ class Base64Command extends Command {
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;
const string = this.options.text ?? this.args.slice(1).join(" ");
if (!string || !string.trim()) return `You need to provide a string to ${command}!`;
if (command === "decode") {
const b64Decoded = Buffer.from(string, "base64").toString("utf8");

View file

@ -6,7 +6,7 @@ class BroadcastCommand extends Command {
return new Promise((resolve) => {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can broadcast messages!";
const message = this.type === "classic" ? this.args.join(" ") : this.options.message;
const message = this.options.message ?? this.args.join(" ");
if (message && message.trim()) {
this.ipc.broadcast("playbroadcast", message);
this.ipc.register("broadcastSuccess", () => {

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class EmoteCommand extends Command {
async run() {
const emoji = this.type === "classic" ? this.content : this.options.emoji;
const emoji = this.options.emoji ?? this.content;
if (!emoji || !emoji.trim()) return "You need to provide an emoji!";
if (emoji.split(" ")[0].match(/^<a?:.+:\d+>$/)) {
return `https://cdn.discordapp.com/emojis/${emoji.split(" ")[0].replace(/^<(a)?:.+:(\d+)>$/, "$2")}.${emoji.split(" ")[0].replace(/^<(a)?:.+:(\d+)>$/, "$1") === "a" ? "gif" : "png"}`;

View file

@ -6,7 +6,7 @@ class EvalCommand extends Command {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can use eval!";
await this.acknowledge();
const code = this.type === "classic" ? this.args.join(" ") : this.options.code;
const code = this.options.code ?? this.args.join(" ");
try {
const evaled = eval(code);
const cleaned = await clean(evaled);

View file

@ -9,7 +9,7 @@ class ExecCommand extends Command {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can use exec!";
await this.acknowledge();
const code = this.type === "classic" ? this.args.join(" ") : this.options.cmd;
const code = this.options.cmd ?? this.args.join(" ");
try {
const execed = await exec(code);
if (execed.stderr) return `\`ERROR\` \`\`\`xl\n${await clean(execed.stderr)}\n\`\`\``;

View file

@ -1,3 +1,4 @@
import { Constants } from "eris";
import database from "../../utils/database.js";
import * as collections from "../../utils/collections.js";
import { random } from "../../utils/misc.js";
@ -5,6 +6,7 @@ import paginator from "../../utils/pagination/pagination.js";
import * as help from "../../utils/help.js";
import Command from "../../classes/command.js";
const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem", "You can run commands in DMs as well, just message the bot with your command - no prefix needed!"];
const argTypes = Object.keys(Constants.ApplicationCommandOptionTypes);
class HelpCommand extends Command {
async run() {
@ -40,12 +42,15 @@ class HelpCommand extends Command {
if (info.flags.length !== 0) {
const flagInfo = [];
for (const flag of info.flags) {
flagInfo.push(`\`--${flag.name}${flag.type ? `=[${flag.type}]` : ""}\` - ${flag.description}`);
if (flag.type === 1) continue;
flagInfo.push(`\`--${flag.name}${flag.type ? `=[${argTypes[flag.type - 1]}]` : ""}\` - ${flag.description}`);
}
if (flagInfo.length !== 0) {
embed.embeds[0].fields.push({
"name": "Flags",
"value": flagInfo.join("\n")
});
}
embed.embeds[0].fields.push({
"name": "Flags",
"value": flagInfo.join("\n")
});
}
return embed;
} else {

View file

@ -8,7 +8,7 @@ import Command from "../../classes/command.js";
class ImageSearchCommand extends Command {
async run() {
if (this.channel.guild && !this.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
const query = this.type === "classic" ? this.args.join(" ") : this.options.query;
const query = this.options.query ?? this.args.join(" ");
if (!query || !query.trim()) return "You need to provide something to search for!";
await this.acknowledge();
const embeds = [];

View file

@ -5,7 +5,7 @@ import Command from "../../classes/command.js";
class LengthenCommand extends Command {
async run() {
await this.acknowledge();
const input = this.type === "classic" ? this.args.join(" ") : this.options.url;
const input = this.options.url ?? this.args.join(" ");
if (!input || !input.trim() || !urlCheck(input)) return "You need to provide a short URL to lengthen!";
if (urlCheck(input)) {
const url = await fetch(encodeURI(input), { redirect: "manual" });

View file

@ -6,7 +6,7 @@ class ReloadCommand extends Command {
return new Promise((resolve) => {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return resolve("Only the bot owner can reload commands!");
const commandName = this.type === "classic" ? this.args.join(" ") : this.options.cmd;
const commandName = this.options.cmd ?? this.args.join(" ");
if (!commandName || !commandName.trim()) return resolve("You need to provide a command to reload!");
this.acknowledge().then(() => {
this.ipc.broadcast("reload", commandName);

View file

@ -7,7 +7,7 @@ import Command from "../../classes/command.js";
class YouTubeCommand extends Command {
async run() {
const query = this.type === "classic" ? this.args.join(" ") : this.options.query;
const query = this.options.query ?? this.args.join(" ");
if (!query || !query.trim()) return "You need to provide something to search for!";
await this.acknowledge();
const messages = [];