perms stuff for settings
This commit is contained in:
parent
d0dbb2d4b5
commit
f65ce7d3eb
@ -1,4 +1,5 @@
|
||||
const { SlashCommand, CommandOption } = require("../../../interfaces");
|
||||
const { Constants: { PermissionNames } } = require('../../../../constants');
|
||||
|
||||
class SettingsCommand extends SlashCommand {
|
||||
|
||||
@ -55,6 +56,15 @@ class SettingsCommand extends SlashCommand {
|
||||
const [setting] = this.client.resolver.components(settingName, 'setting');
|
||||
if (!setting) return interaction.reply('Something went wrong, could not find setting');
|
||||
|
||||
if (setting.clientPermissions.length) {
|
||||
const missing = guild.me.permissions.missing(setting.clientPermissions);
|
||||
if (missing.length) return interaction.reply({
|
||||
emoji: 'failure',
|
||||
index: 'SETTING_MISSINGCLIENTPERMISSIONS',
|
||||
params: { permissions: missing.map((m) => `\`${PermissionNames[m]}\``).join(', ') }
|
||||
});
|
||||
}
|
||||
|
||||
await interaction.deferReply();
|
||||
const settings = await guild.settings();
|
||||
if (!Object.keys(opts).length) return this._showSetting(interaction, setting);
|
||||
@ -66,15 +76,8 @@ class SettingsCommand extends SlashCommand {
|
||||
|
||||
if (result) {
|
||||
|
||||
const obj = { components: [] };
|
||||
if (result.message) obj.content = result.message;
|
||||
else if (result.index) {
|
||||
// Make setting name available as a param
|
||||
obj.template = { params: {}, ...result };
|
||||
obj.template.params.setting = setting.name;
|
||||
}
|
||||
|
||||
if (result.embeds) obj.embeds = result.embeds;
|
||||
const obj = { components: [], ...result };
|
||||
obj.params.setting = setting.name;
|
||||
|
||||
if (!result.error) {
|
||||
settings[setting.name] = _setting;
|
||||
@ -87,19 +90,15 @@ class SettingsCommand extends SlashCommand {
|
||||
} catch (err) {
|
||||
this.client.logger.error(`Error during setting execution:\n${err.stack || err}`);
|
||||
await interaction.editReply({
|
||||
template: {
|
||||
index: 'SETTINGS_ERROR',
|
||||
params: { resolveable: setting.resolveable }
|
||||
},
|
||||
index: 'SETTINGS_ERROR',
|
||||
params: { resolveable: setting.resolveable },
|
||||
emoji: 'failure'
|
||||
});
|
||||
}
|
||||
|
||||
if (!interaction.replied) await interaction.reply({
|
||||
template: {
|
||||
index: 'SETTINGS_NO_REPLY',
|
||||
params: { resolveable: setting.resolveable }
|
||||
}
|
||||
index: 'SETTINGS_NO_REPLY',
|
||||
params: { resolveable: setting.resolveable }
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user