2022-09-18 11:57:22 +01:00
|
|
|
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
2022-04-24 14:46:37 +01:00
|
|
|
import SettingsHelper from "../helpers/SettingsHelper";
|
|
|
|
import { Command } from "../type/command";
|
|
|
|
|
|
|
|
export default class Disable extends Command {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
super.CommandBuilder = new SlashCommandBuilder()
|
|
|
|
.setName('disable')
|
|
|
|
.setDescription('Disables a command')
|
|
|
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName('add')
|
|
|
|
.setDescription('Disables a command for the server')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName('name')
|
|
|
|
.setDescription('The name of the command')
|
|
|
|
.setRequired(true)))
|
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName('remove')
|
|
|
|
.setDescription('Enables a command for the server')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName('name')
|
|
|
|
.setDescription('The name of the command')
|
|
|
|
.setRequired(true)));
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
public override async execute(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
switch (interaction.options.getSubcommand()) {
|
2022-04-24 14:46:37 +01:00
|
|
|
case "add":
|
2022-09-18 11:57:22 +01:00
|
|
|
await this.Add(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
break;
|
|
|
|
case "remove":
|
2022-09-18 11:57:22 +01:00
|
|
|
await this.Remove(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply('Subcommand not found.');
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
private async Add(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.guildId) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const commandName = interaction.options.get('name');
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
if (!commandName || !commandName.value) {
|
|
|
|
await interaction.reply('Fields are required.');
|
2022-04-24 14:46:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
2022-04-24 14:46:37 +01:00
|
|
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
disabledCommands?.push(commandName.value.toString());
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply(`Disabled command ${commandName.value}`);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
private async Remove(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.guildId) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const commandName = interaction.options.get('name');
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
if (!commandName || !commandName.value) {
|
|
|
|
await interaction.reply('Fields are required.');
|
2022-04-24 14:46:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
2022-04-24 14:46:37 +01:00
|
|
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName.value!.toString());
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
if (disabledCommandsInstance! > -1) {
|
|
|
|
disabledCommands?.splice(disabledCommandsInstance!, 1);
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply(`Enabled command ${commandName.value}`);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
}
|