2020-05-24 23:43:27 +02:00
|
|
|
const { Setting } = require('../../../../interfaces/');
|
|
|
|
|
|
|
|
class NicknameLogs extends Setting {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'nicknameLog',
|
|
|
|
module: 'moderation',
|
|
|
|
aliases: [
|
|
|
|
'nicknameLogs',
|
|
|
|
'nickLog',
|
|
|
|
'nickLogs'
|
|
|
|
],
|
2020-08-04 11:35:28 +02:00
|
|
|
tags: ['log', 'logs', 'logging'],
|
2020-05-24 23:43:27 +02:00
|
|
|
usage: '<value>',
|
|
|
|
resolve: 'GUILD',
|
|
|
|
examples: [
|
|
|
|
'nicklogs reset',
|
2020-05-25 13:13:34 +02:00
|
|
|
'nicklogs off',
|
2020-05-24 23:43:27 +02:00
|
|
|
'nicklogs #channel'
|
|
|
|
],
|
|
|
|
default: {
|
|
|
|
nicknameLog: {
|
2020-05-25 13:13:34 +02:00
|
|
|
channel: null
|
2020-05-24 23:43:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async handle(message, params) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line init-declarations
|
|
|
|
let index, changes, action;
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let [method, ...args] = params;
|
|
|
|
method = method.toLowerCase();
|
|
|
|
|
|
|
|
const setting = message.guild._settings[this.index] || this.default[this.index];
|
|
|
|
const { guild } = message;
|
|
|
|
|
2020-05-25 13:13:34 +02:00
|
|
|
if (this.client.resolver.resolveBoolean(method) === false) {
|
2020-05-24 23:43:27 +02:00
|
|
|
|
2020-05-25 13:13:34 +02:00
|
|
|
setting.channel = null;
|
2020-05-24 23:43:27 +02:00
|
|
|
index = 'S_NICKNAMELOG_TOGGLE'
|
|
|
|
changes = message.format('ON_OFF_TOGGLE', { toggle: false }, true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2020-06-19 15:38:56 +02:00
|
|
|
const channel = await guild.resolveChannel(method);
|
2020-05-24 23:43:27 +02:00
|
|
|
if (!channel) return {
|
|
|
|
msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: method }),
|
|
|
|
error: true
|
|
|
|
};
|
2020-06-19 20:29:54 +02:00
|
|
|
if(channel.type !== 'text') return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_TYPE', { type: channel.type })
|
|
|
|
};
|
|
|
|
|
|
|
|
const perms = channel.permissionsFor(guild.me);
|
|
|
|
const missingPerms = [];
|
|
|
|
if(!perms.has('SEND_MESSAGES')) missingPerms.push('SEND_MESSAGES');
|
|
|
|
if(!perms.has('VIEW_CHANNEL')) missingPerms.push('VIEW_CHANNEL');
|
|
|
|
|
|
|
|
if(missingPerms.length) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
|
|
|
|
};
|
2020-05-24 23:43:27 +02:00
|
|
|
|
|
|
|
index = 'S_NICKNAMELOG_CHANNEL';
|
|
|
|
changes = channel.name;
|
|
|
|
setting.channel = channel.id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.guild._updateSettings({ [this.index]: setting });
|
|
|
|
return {
|
|
|
|
msg: message.format(index, { changed: changes || '', action: message.format(action) })
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async fields(guild) {
|
|
|
|
const setting = guild._settings[this.index];
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: '》Channel',
|
2020-06-19 15:38:56 +02:00
|
|
|
value: await guild.resolveChannel(setting?.channel) || '`N/A`',
|
2020-05-24 23:43:27 +02:00
|
|
|
inline: true
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NicknameLogs;
|