2021-08-19 14:19:14 +00:00
|
|
|
import db from "../../utils/database.js";
|
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
import * as collections from "../../utils/collections.js";
|
2021-08-13 03:28:09 +00:00
|
|
|
|
|
|
|
class CommandCommand extends Command {
|
|
|
|
async run() {
|
2022-03-31 05:42:03 +00:00
|
|
|
if (!this.channel.guild) return "This command only works in servers!";
|
2021-11-03 00:43:37 +00:00
|
|
|
const owners = process.env.OWNER.split(",");
|
2022-04-05 03:05:28 +00:00
|
|
|
if (!this.member.permissions.has("administrator") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!";
|
2022-07-07 00:16:38 +00:00
|
|
|
if (this.args.length === 0) return "You need to provide whether you want to enable/disable a command!";
|
2021-08-13 03:28:09 +00:00
|
|
|
if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!";
|
2022-07-07 00:16:38 +00:00
|
|
|
if (!this.args[1]) return "You need to provide what command to enable/disable!";
|
|
|
|
if (!collections.commands.has(this.args[1].toLowerCase()) && !collections.aliases.has(this.args[1].toLowerCase())) return "That isn't a command!";
|
2021-08-13 03:28:09 +00:00
|
|
|
|
2022-03-31 05:42:03 +00:00
|
|
|
const guildDB = await db.getGuild(this.channel.guild.id);
|
2022-01-15 05:26:38 +00:00
|
|
|
const disabled = guildDB.disabled_commands ?? guildDB.disabledCommands;
|
2022-07-07 00:16:38 +00:00
|
|
|
const command = collections.aliases.get(this.args[1].toLowerCase()) ?? this.args[1].toLowerCase();
|
2021-08-13 03:28:09 +00:00
|
|
|
|
|
|
|
if (this.args[0].toLowerCase() === "disable") {
|
2021-08-18 13:07:55 +00:00
|
|
|
if (command === "command") return "You can't disable that command!";
|
2022-07-23 21:02:04 +00:00
|
|
|
if (disabled?.includes(command)) return "That command is already disabled!";
|
2021-08-13 03:28:09 +00:00
|
|
|
|
2022-03-31 05:42:03 +00:00
|
|
|
await db.disableCommand(this.channel.guild.id, command);
|
2021-08-13 03:28:09 +00:00
|
|
|
return `The command has been disabled. To re-enable it, just run \`${guildDB.prefix}command enable ${command}\`.`;
|
|
|
|
} else if (this.args[0].toLowerCase() === "enable") {
|
2022-07-23 21:02:04 +00:00
|
|
|
if (!disabled?.includes(command)) return "That command isn't disabled!";
|
2021-08-13 03:28:09 +00:00
|
|
|
|
2022-03-31 05:42:03 +00:00
|
|
|
await db.enableCommand(this.channel.guild.id, command);
|
2021-08-13 03:28:09 +00:00
|
|
|
return `The command \`${command}\` has been re-enabled.`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static description = "Enables/disables a command for a server";
|
|
|
|
static aliases = ["cmd"];
|
|
|
|
static arguments = ["[enable/disable]", "[command]"];
|
2022-06-28 21:15:31 +00:00
|
|
|
static slashAllowed = false;
|
|
|
|
static directAllowed = false;
|
2021-08-13 03:28:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 05:26:38 +00:00
|
|
|
export default CommandCommand;
|