112 lines
3.5 KiB
JavaScript
112 lines
3.5 KiB
JavaScript
const { Setting } = require('../../../../interfaces/');
|
|
|
|
class StickyRoleSetting extends Setting {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'stickyrole',
|
|
module: 'utility',
|
|
aliases: [
|
|
'sticky',
|
|
'stickyroles'
|
|
],
|
|
usage: '<value>',
|
|
examples: [
|
|
'stickyrole on',
|
|
'stickyrole add moderator member'
|
|
],
|
|
guarded: false,
|
|
resolve: 'GUILD',
|
|
default: {
|
|
stickyrole: {
|
|
roles: []
|
|
}
|
|
},
|
|
custom: true,
|
|
premium: 1
|
|
});
|
|
|
|
}
|
|
|
|
async handle(message, params) {
|
|
|
|
const { guild } = message;
|
|
const setting = guild._settings[this.index];
|
|
const { resolver } = this.client;
|
|
const langParams = {};
|
|
let index = null;
|
|
|
|
const response = await resolver.resolveMethod(params, null, setting.roles, resolver.resolveRoles.bind(resolver), guild);
|
|
if (!response) return {
|
|
error: true,
|
|
msg: message.format('ERR_INVALID_METHOD', { method: params[0] })
|
|
};
|
|
|
|
const { method } = response;
|
|
|
|
if (method === 'on') {
|
|
setting.roles = guild.roles.cache.map((r) => r.id);
|
|
index = 'S_STICKYROLE_TOGGLE';
|
|
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: true }, true);
|
|
} else if (method === 'off') {
|
|
setting.roles = [];
|
|
index = 'S_STICKYROLE_TOGGLE';
|
|
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: false }, true);
|
|
} else if (method === 'add') {
|
|
|
|
const roles = response.resolved;
|
|
setting.roles = response.result;
|
|
|
|
index = 'S_STICKYROLE_ADD';
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
} else if (method === 'remove') {
|
|
|
|
const roles = response.resolved;
|
|
setting.roles = response.result;
|
|
|
|
index = 'S_STICKYROLE_REMOVE';
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `');
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
} else if (method === 'set') {
|
|
|
|
const roles = response.resolved;
|
|
setting.roles = roles.map((r) => r.id);
|
|
|
|
index = 'S_STICKYROLE_SET';
|
|
const changed = roles.filter((r) => response.changed.includes(r.id)).map((r) => r.name).join('`, `')
|
|
langParams.changes = changed.length ? changed : 'N/A';
|
|
|
|
} else if (method === 'list') {
|
|
|
|
index = 'S_STICKYROLE_LIST';
|
|
langParams.list = response.resolved.map((r) => r.name).join(', ');
|
|
|
|
}
|
|
|
|
await message.guild._updateSettings({ [this.index]: setting });
|
|
return {
|
|
error: false,
|
|
msg: message.format(index, langParams)
|
|
};
|
|
|
|
}
|
|
|
|
async fields(guild) {
|
|
const setting = guild._settings[this.index] || this.default[this.index];
|
|
const roles = setting.roles ? await this.client.resolver.resolveRoles(setting.roles) : null;
|
|
return [
|
|
{
|
|
name: '》 Roles',
|
|
value: roles ? roles.map((r) => r.name) : 'N/A',
|
|
inline: false
|
|
}
|
|
];
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = StickyRoleSetting; |