forked from Galactic/galactic-bot
protection setting
This commit is contained in:
parent
7fbd30c30e
commit
7613f650c7
122
structure/client/components/settings/moderation/Protection.js
Normal file
122
structure/client/components/settings/moderation/Protection.js
Normal file
@ -0,0 +1,122 @@
|
||||
const { Setting } = require('../../../../interfaces/');
|
||||
|
||||
class ProtectionSetting extends Setting {
|
||||
|
||||
constructor(client) {
|
||||
|
||||
super(client, {
|
||||
name: 'protection',
|
||||
module: 'moderation',
|
||||
aliases: [
|
||||
|
||||
],
|
||||
usage: '<method|value> [value..]',
|
||||
examples: [
|
||||
'protection type <role|position>',
|
||||
'protection add <role..>',
|
||||
'protection remove <role..>'
|
||||
],
|
||||
guarded: false,
|
||||
resolve: 'GUILD',
|
||||
default: {
|
||||
protection: {
|
||||
type: 'position',
|
||||
enabled: false,
|
||||
roles: []
|
||||
}
|
||||
},
|
||||
custom: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async handle(message, params) {
|
||||
|
||||
const { guild } = message;
|
||||
const { resolver } = this.client;
|
||||
const setting = guild._settings[this.index];
|
||||
|
||||
let method = params[0].toLowerCase(),
|
||||
index = null;
|
||||
|
||||
const langParams = {};
|
||||
|
||||
if (method === 'type') {
|
||||
|
||||
if (!params[1]) return message.format('MISSING_ARGS');
|
||||
const value = params[1].toLowerCase();
|
||||
if (!['role', 'position'].includes(value)) return message.format('S_PROTECTION_INVALID_ARGS');
|
||||
setting.type = value;
|
||||
|
||||
index = 'S_PROTECTION_TYPE';
|
||||
langParams.type = value;
|
||||
|
||||
} else {
|
||||
|
||||
const response = await resolver.resolveMethod(params, null, setting.roles, resolver.resolveRoles.bind(resolver), guild);
|
||||
if (!response) return message.format('INVALID_METHOD', { method });
|
||||
({ method } = response);
|
||||
|
||||
if (method === 'add') {
|
||||
|
||||
setting.roles = response.result;
|
||||
setting.enabled = true;
|
||||
|
||||
index = 'S_PROTECTION_ADD';
|
||||
langParams.changes = response.resolved.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
||||
|
||||
} else if (method === 'remove') {
|
||||
|
||||
setting.roles = response.result;
|
||||
setting.enabled = setting.roles.length && true;
|
||||
|
||||
index = 'S_PROTECTION_REMOVE';
|
||||
langParams.changes = response.resolved.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
||||
|
||||
} else if (method === 'set') {
|
||||
|
||||
setting.roles = response.result;
|
||||
setting.enabled = true;
|
||||
|
||||
index = 'S_PROTECTION_SET';
|
||||
langParams.changes = response.resolved.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
||||
|
||||
} else if (method === 'list') {
|
||||
|
||||
index = 'S_AUTOROLE_LIST';
|
||||
langParams.list = response.resolved.map((r) => r.name).join(', ');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await guild._updateSettings({
|
||||
[this.index]: setting
|
||||
});
|
||||
return { error: false, msg: message.format(index, langParams) };
|
||||
|
||||
}
|
||||
|
||||
async fields(guild) {
|
||||
const setting = guild._settings[this.index];
|
||||
const roles = setting?.roles ? await Promise.all(setting.roles.map(async (role) => guild.resolveRole(role))) : undefined;
|
||||
return [
|
||||
{
|
||||
name: '》Enabled',
|
||||
value: setting.enabled,
|
||||
inline: true
|
||||
}, {
|
||||
name: '》Type',
|
||||
value: setting.type,
|
||||
inline: true
|
||||
}, {
|
||||
name: '》Roles',
|
||||
value: roles?.map(r => r.name).join(', ') || 'N/A',
|
||||
inline: false
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ProtectionSetting;
|
Loading…
Reference in New Issue
Block a user