Consolidated to setup command

This commit is contained in:
Skylar Grant 2023-02-19 20:34:22 -05:00
parent dbefee209d
commit d783da4b83
2 changed files with 30 additions and 26 deletions

View File

@ -1,26 +0,0 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const fn = require('../modules/functions.js');
const strings = require('../data/strings.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('reset')
.setDescription('Reset all message assignments in your server')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
execute(interaction) {
interaction.deferReply({ ephemeral: true }).then(() => {
fn.reset(interaction).then(res => {
interaction.editReply(fn.builders.embed(strings.status.reset)).catch(err => {
console.error(err);
});
}).catch(err => {
console.error(err);
interaction.editReply(strings.status.resetError).catch(err => {
console.error(err);
});
});
}).catch(err => {
console.error(err);
});
},
};

View File

@ -39,6 +39,15 @@ module.exports = {
.addSubcommand(sc => .addSubcommand(sc =>
sc.setName('view') sc.setName('view')
.setDescription('View your server\'s configuration')) .setDescription('View your server\'s configuration'))
.addSubcommand(sc =>
sc.setName('reset')
.setDescription('Remove all server configuration from the database')
.addBooleanOption(o =>
o.setName('confirm')
.setDescription('WARNING THIS IS IRREVERSIBLE')
.setRequired(true)
)
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator), .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) { async execute(interaction) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
@ -87,6 +96,27 @@ module.exports = {
await interaction.editReply(fn.builders.errorEmbed("There was an error running the command.")); await interaction.editReply(fn.builders.errorEmbed("There was an error running the command."));
} }
break; break;
case "reset":
if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
if (interaction.options.getBoolean('confirm')) {
fn.reset(interaction).then(res => {
interaction.editReply(fn.builders.embed(strings.status.reset)).catch(err => {
console.error(err);
});
}).catch(err => {
console.error(err);
interaction.editReply(strings.status.resetError).catch(err => {
console.error(err);
});
});
} else {
await interaction.editReply(fn.builders.embed("You must select 'true' to confirm setup reset. No changes have been made.")).catch(e => console.error(e));
}
} else {
throw "Guild doesn't exist in database!";
}
break;
default: default:
await interaction.editReply(fn.builders.errorEmbed(strings.error.invalidSubcommand)).catch(e => console.error(e)); await interaction.editReply(fn.builders.errorEmbed(strings.error.invalidSubcommand)).catch(e => console.error(e));
break; break;