2020-06-10 16:49:07 +02:00
|
|
|
const { Setting } = require('../../../../interfaces/');
|
|
|
|
|
|
|
|
class AutoroleSetting extends Setting {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'autorole',
|
|
|
|
module: 'utility',
|
|
|
|
aliases: [
|
|
|
|
|
|
|
|
],
|
|
|
|
usage: '<method|value> [value..]',
|
|
|
|
examples: [
|
|
|
|
'autorole add role',
|
|
|
|
'autorole remove role'
|
|
|
|
],
|
|
|
|
guarded: false,
|
|
|
|
resolve: 'GUILD',
|
|
|
|
default: {
|
|
|
|
autorole: {
|
|
|
|
roles: [],
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
custom: true
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async handle(message, params) {
|
|
|
|
|
2020-07-11 22:33:44 +02:00
|
|
|
const setting = message.guild._settings[this.index];
|
2020-06-10 16:49:07 +02:00
|
|
|
const { guild } = message;
|
|
|
|
const { resolver } = this.client;
|
|
|
|
const response = await resolver.resolveMethod(params, null, setting.roles, resolver.resolveRoles.bind(resolver), guild);
|
|
|
|
|
|
|
|
let index = null,
|
|
|
|
langParams = {};
|
|
|
|
|
|
|
|
if (!response) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_INVALID_METHOD', { method: params[0] })
|
|
|
|
};
|
|
|
|
|
|
|
|
const { method } = response;
|
|
|
|
|
|
|
|
//console.log(response);
|
|
|
|
|
|
|
|
if (method === 'add') {
|
|
|
|
|
|
|
|
const roles = response.resolved;
|
|
|
|
setting.roles = response.result;
|
|
|
|
setting.enabled = true;
|
|
|
|
|
|
|
|
index = 'S_AUTOROLE_ADD';
|
2020-08-16 09:27:49 +02:00
|
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
2020-06-10 16:49:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'remove') {
|
|
|
|
|
|
|
|
const roles = response.resolved;
|
|
|
|
setting.roles = response.result;
|
|
|
|
setting.enabled = setting.roles.length && true;
|
|
|
|
|
|
|
|
index = 'S_AUTOROLE_REMOVE';
|
2020-08-16 09:27:49 +02:00
|
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
2020-06-10 16:49:07 +02:00
|
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
|
|
|
|
} else if (method === 'list') {
|
|
|
|
|
|
|
|
index = 'S_AUTOROLE_LIST';
|
2020-08-16 09:27:49 +02:00
|
|
|
langParams.list = response.resolved.map((r) => r.name).join(', ');
|
2020-06-10 16:49:07 +02:00
|
|
|
|
|
|
|
} else if (method === 'set') {
|
|
|
|
|
|
|
|
const roles = response.resolved;
|
2020-08-16 09:27:49 +02:00
|
|
|
setting.roles = roles.map((r) => r.id);
|
2020-06-10 16:49:07 +02:00
|
|
|
setting.enabled = roles.length && true;
|
|
|
|
|
|
|
|
index = 'S_AUTOROLE_SET';
|
2020-08-16 09:27:49 +02:00
|
|
|
langParams.changes = roles.map((r) => r.name).join('`, `');
|
2020-06-10 16:49:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.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 [
|
|
|
|
{
|
2020-08-16 09:27:49 +02:00
|
|
|
name: '》 Enabled',
|
2020-06-10 16:49:07 +02:00
|
|
|
value: setting.enabled,
|
|
|
|
inline: false
|
|
|
|
}, {
|
2020-08-16 09:27:49 +02:00
|
|
|
name: '》 Roles',
|
|
|
|
value: roles?.map((r) => r.name).join(', ') || 'N/A',
|
2020-06-10 16:49:07 +02:00
|
|
|
inline: false
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AutoroleSetting;
|