diff --git a/src/structure/components/settings/administration/Protection.js b/src/structure/components/settings/administration/Protection.js new file mode 100644 index 0000000..c84c921 --- /dev/null +++ b/src/structure/components/settings/administration/Protection.js @@ -0,0 +1,88 @@ +const Util = require("../../../../Util"); +const { Setting, CommandOption } = require("../../../interfaces"); + +class ProtectionSetting extends Setting { + + constructor(client) { + + super(client, { + name: 'protection', + description: 'Select protected roles', + module: 'administration', + display: 'Protection', + default: { + type: 'position', + roles: [] + }, + commandOptions: [ + new CommandOption({ + type: 'STRING', + name: 'type', + description: 'Select protection type', + choices: [ + { name: 'role', value: 'role' }, + { name: 'position', value: 'position' } + ] + }), + new CommandOption({ + type: 'STRING', + name: 'method', + description: '', + choices: [ + { name: 'add', value: 'add' }, + { name: 'remove', value: 'remove' }, + { name: 'set', value: 'set' }, + { name: 'reset', value: 'reset' }, + ] + }) + ] + }); + + } + + async execute(interaction, opts, setting) { + + if (opts.type) setting.type = opts.type.value; + + const method = opts.method?.value; + if (method) { + + const response = await this._prompt(interaction, { + index: `SETTING_PROMPT_${method.toUpperCase()}`, + params: { list: 'roles' } + }); + + const { guild } = interaction; + const params = Util.parseQuotes(response).map(([param]) => param); + const roles = await guild.resolveRoles(params); + if (!roles.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: 'roles' } }; + + this[method](setting.roles, roles.map((r) => r.id)); + + } + + return { + error: false, + index: 'SETTING_SUCCESS_ALT' + }; + + } + + async fields(guild) { + const setting = guild._settings[this.index]; + return [ + { + name: 'GENERAL_TYPE', + value: `\`${setting.type}\``, + inline: true + }, { + name: 'IGNORED_ROLES', + value: setting.roles.map((r) => `<@&${r.id}>`).join(' ') || '`N/A`', + inline: true + } + ]; + } + +} + +module.exports = ProtectionSetting; \ No newline at end of file