2020-06-10 16:48:07 +02:00
|
|
|
const { Setting } = require('../../../../interfaces');
|
|
|
|
|
|
|
|
class IgnoreSetting extends Setting {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
2020-08-19 10:26:29 +02:00
|
|
|
name: 'ignoreChannels',
|
2020-08-16 09:27:49 +02:00
|
|
|
module: 'administration',
|
2020-06-10 16:48:07 +02:00
|
|
|
aliases: [
|
2020-08-19 10:26:29 +02:00
|
|
|
'ignoreChannel',
|
|
|
|
'channelIgnore',
|
|
|
|
'channelIgnores',
|
|
|
|
'ignore'
|
2020-06-10 16:48:07 +02:00
|
|
|
],
|
|
|
|
usage: '<method|value> [value..]',
|
|
|
|
examples: [
|
|
|
|
'ignore add #channel',
|
|
|
|
'ignore remove #channel',
|
|
|
|
'ignore bypass add role',
|
|
|
|
'ignore bypass remove role'
|
|
|
|
],
|
|
|
|
guarded: false,
|
|
|
|
resolve: 'GUILD',
|
|
|
|
default: {
|
|
|
|
ignore: {
|
|
|
|
channels: [],
|
|
|
|
enabled: false,
|
|
|
|
roleBypass: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
custom: true
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async handle(message, params) {
|
|
|
|
|
|
|
|
let index = null,
|
|
|
|
langParams = {},
|
|
|
|
method = null;
|
|
|
|
|
|
|
|
const setting = message.guild._settings[this.index] || this.default[this.index];
|
|
|
|
const { guild } = message;
|
|
|
|
const { resolver } = this.client;
|
|
|
|
const response = await resolver.resolveMethod(params, null, setting.channels, resolver.resolveChannels.bind(resolver), guild);
|
|
|
|
|
|
|
|
if (!response) method = params.shift();
|
|
|
|
else ({ method } = response);
|
|
|
|
|
|
|
|
if (method === 'add') {
|
|
|
|
|
|
|
|
const channels = response.resolved;
|
|
|
|
setting.channels = response.result;
|
|
|
|
setting.enabled = true;
|
|
|
|
|
|
|
|
index = 'S_IGNORE_ADD';
|
2020-07-28 05:00:24 +02:00
|
|
|
const changed = channels.filter((c) => response.changed.includes(c.id)).map((c) => c.name).join('`, `');
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'remove') {
|
|
|
|
|
|
|
|
const channels = response.resolved;
|
|
|
|
setting.channels = response.result;
|
|
|
|
setting.enabled = setting.channels.length && true;
|
|
|
|
|
|
|
|
index = 'S_IGNORE_REMOVE';
|
2020-07-28 05:00:24 +02:00
|
|
|
const changed = channels.filter((c) => response.changed.includes(c.id)).map((c) => c.name).join('`, `');
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'list') {
|
|
|
|
|
|
|
|
const roles = await resolver.resolveRoles(setting.roleBypass, false, guild);
|
|
|
|
|
|
|
|
index = 'S_IGNORE_LIST';
|
2020-07-28 05:00:24 +02:00
|
|
|
const ch = response.resolved ? response.resolved?.map((c) => c.name).join('`, `') : '';
|
|
|
|
const r = roles.length ? roles.map((r) => r.name).join('`, `') : '';
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.channels = ch.length ? ch : 'N/A';
|
|
|
|
langParams.roles = r.length ? r : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'set') {
|
|
|
|
|
|
|
|
const channels = response.resolved;
|
2020-07-28 05:00:24 +02:00
|
|
|
setting.channels = channels.map((c) => c.id);
|
2020-06-10 16:48:07 +02:00
|
|
|
setting.enabled = channels.length && true;
|
|
|
|
|
|
|
|
index = 'S_IGNORE_SET';
|
2020-07-28 05:00:24 +02:00
|
|
|
const ch = channels.map((c) => c.name).join('`, `');
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.changes = ch.length ? ch : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'bypass') {
|
|
|
|
|
|
|
|
const response = await resolver.resolveMethod(params, null, setting.roleBypass, resolver.resolveRoles.bind(resolver), guild);
|
|
|
|
|
|
|
|
if (response.method === 'add') {
|
|
|
|
|
|
|
|
const roles = response.resolved;
|
|
|
|
setting.roleBypass = response.result;
|
|
|
|
|
|
|
|
index = 'S_IGNORE_BYPASS_ADD';
|
2020-07-28 05:00:24 +02:00
|
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
|
|
|
} else if (response.method === 'remove') {
|
|
|
|
|
|
|
|
const roles = response.resolved;
|
|
|
|
setting.roleBypass = response.result;
|
|
|
|
|
|
|
|
index = 'S_IGNORE_BYPASS_REMOVE';
|
2020-07-28 05:00:24 +02:00
|
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
2020-06-10 16:48:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
2020-07-28 05:00:24 +02:00
|
|
|
} else return { error: true, msg: message.format('ERR_INVALID_SUBMETHOD', { submethod: params[0] }) };
|
2020-06-10 16:48:07 +02:00
|
|
|
|
|
|
|
} else return { error: true, msg: message.format('ERR_INVALID_METHOD', { method }) };
|
|
|
|
|
|
|
|
await message.guild._updateSettings({ [this.index]: setting });
|
|
|
|
return { error: false, msg: message.format(index, langParams) };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async fields(guild) {
|
|
|
|
const setting = guild._settings[this.index];
|
2020-06-19 15:38:56 +02:00
|
|
|
const roles = setting?.roleBypass ? await Promise.all(setting.roleBypass.map(async (role) => await guild.resolveRole(role))) : undefined;
|
|
|
|
const channels = setting?.channels ? await Promise.all(setting.channels.map(async (ch) => await guild.resolveChannel(ch))) : undefined;
|
2020-06-10 16:48:07 +02:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2020-08-16 09:27:49 +02:00
|
|
|
name: '》 Status',
|
|
|
|
value: guild.format('SETTING_STATUS', { bool: Boolean(setting?.enabled) }, true)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Channels',
|
|
|
|
value: channels?.map((c) => c.name).join(', ') || '`N/A`'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Roles',
|
|
|
|
value: roles?.map((r) => r.name).join(', ') || '`N/A`'
|
2020-06-10 16:48:07 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = IgnoreSetting;
|