protection

This commit is contained in:
Erik 2022-01-18 16:33:31 +02:00
parent 6f108a8323
commit b2921ac314
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589

View File

@ -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;