From b2921ac314365220eab4917b36f03bdce6080ead Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 18 Jan 2022 16:33:31 +0200 Subject: [PATCH] protection --- .../settings/administration/Protection.js | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/structure/components/settings/administration/Protection.js 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