2020-05-22 22:13:47 +02:00
|
|
|
const { Setting } = require('../../../../interfaces/');
|
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
const CONSTANTS = {
|
2020-05-24 10:54:33 +02:00
|
|
|
INFRACTIONS: ['note', 'warn', 'mute', 'unmute', 'lockdown', 'unlockdown', 'kick', 'ban', 'unban', 'vcmute', 'vcunmute', 'vckick', 'vcban', 'vcunban', 'prune', 'slowmode', 'dehoist', 'addrole', 'removerole', 'nickname']
|
2020-05-24 00:11:15 +02:00
|
|
|
};
|
|
|
|
|
2020-05-24 10:54:33 +02:00
|
|
|
class ModerationLogsSetting extends Setting {
|
2020-05-22 22:13:47 +02:00
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'moderationLog',
|
|
|
|
module: 'moderation',
|
|
|
|
aliases: [
|
|
|
|
'moderationLogs',
|
|
|
|
'modLog',
|
|
|
|
'modLogs'
|
|
|
|
],
|
2020-05-24 23:42:28 +02:00
|
|
|
usage: '<method|value> [value..]',
|
2020-05-22 22:13:47 +02:00
|
|
|
resolve: 'GUILD',
|
|
|
|
examples: [
|
2020-05-24 10:54:33 +02:00
|
|
|
'modlog <add|remove|list> <infraction-type..>',
|
|
|
|
'modlog #moderation-log',
|
2020-05-25 13:13:34 +02:00
|
|
|
'modlog reset',
|
|
|
|
'modlog off'
|
2020-05-22 22:13:47 +02:00
|
|
|
],
|
|
|
|
default: {
|
2020-05-24 10:54:33 +02:00
|
|
|
moderationLog: {
|
|
|
|
channel: null,
|
|
|
|
infractions: ['warn','mute','unmute','lockdown','unlockdown','kick','ban','unban','vcmute','vcunmute','vckick','vcban','vcunban']
|
2020-05-22 22:13:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-04 19:59:09 +02:00
|
|
|
async handle(message, params) {
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-06-04 19:59:09 +02:00
|
|
|
const setting = message.guild._settings.moderationLog;
|
|
|
|
const response = await this.resolveMethod(params, CONSTANTS.INFRACTIONS, setting.infractions);
|
2020-05-24 00:11:15 +02:00
|
|
|
|
|
|
|
if (response) {
|
2020-06-04 19:59:09 +02:00
|
|
|
console.log(response);
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-06-04 19:59:09 +02:00
|
|
|
if (params.length < 2 && response.method !== 'list') return {
|
2020-05-24 23:42:28 +02:00
|
|
|
msg: message.format('MISSING_ARGS'),
|
2020-05-22 22:13:47 +02:00
|
|
|
error: true
|
|
|
|
}
|
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
let index;
|
|
|
|
if (response.method === 'add') {
|
|
|
|
setting.infractions = response.result;
|
2020-05-24 10:54:33 +02:00
|
|
|
index = 'S_MODERATIONLOG_ADD';
|
2020-05-24 00:11:15 +02:00
|
|
|
} else if (response.method === 'remove') {
|
|
|
|
setting.infractions = response.result;
|
2020-05-24 10:54:33 +02:00
|
|
|
index = 'S_MODERATIONLOG_REMOVE';
|
2020-05-24 00:11:15 +02:00
|
|
|
} else if (response.method === 'list') {
|
2020-05-22 22:13:47 +02:00
|
|
|
return {
|
2020-05-24 10:54:33 +02:00
|
|
|
msg: message.format('S_MODERATIONLOG_LIST', { list: setting.infractions.join('`, `') })
|
2020-05-24 00:11:15 +02:00
|
|
|
}
|
2020-05-25 13:13:34 +02:00
|
|
|
} else if (response.method === 'off') {
|
|
|
|
setting.channel = null;
|
|
|
|
index = 'S_MODERATIONLOG_OFF'
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
msg: message.format('ERR_INVALID_METHOD', {
|
|
|
|
method: response.method
|
|
|
|
}),
|
|
|
|
error: true
|
|
|
|
}
|
|
|
|
}
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
if(response.changed.length) await message.guild._updateSettings({ [this.index]: setting });
|
|
|
|
return { msg: message.format(index, { list: response.changed.length ? response.changed.join('`, `') : 'N/A' }) };
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
} else {
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
let [channel] = params;
|
|
|
|
|
|
|
|
channel = message.guild.resolveChannel(channel);
|
|
|
|
if (!channel) return {
|
2020-05-24 10:54:33 +02:00
|
|
|
msg: message.format('S_MODERATIONLOG_CHANNEL404', { val: params[0] }),
|
2020-05-24 00:11:15 +02:00
|
|
|
error: true
|
|
|
|
};
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-05-24 00:11:15 +02:00
|
|
|
setting.channel = channel.id;
|
|
|
|
await message.guild._updateSettings({ [this.index]: setting }); return {
|
2020-05-24 10:54:33 +02:00
|
|
|
msg: message.format('S_MODERATIONLOG_CHANNEL_SUCCESS', { channel: channel.name }),
|
2020-05-24 00:11:15 +02:00
|
|
|
error: false
|
|
|
|
};
|
2020-05-22 22:13:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fields(guild) {
|
2020-05-24 23:42:28 +02:00
|
|
|
const setting = guild._settings[this.index];
|
2020-05-22 22:13:47 +02:00
|
|
|
return [
|
|
|
|
{
|
2020-05-24 10:54:33 +02:00
|
|
|
name: '》Channel',
|
2020-05-24 23:42:28 +02:00
|
|
|
value: guild.resolveChannel(setting?.channel) || '`N/A`',
|
2020-05-22 22:13:47 +02:00
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
2020-05-24 10:54:33 +02:00
|
|
|
name: '》Logged Infractions',
|
2020-05-24 23:42:28 +02:00
|
|
|
value: setting?.infractions.map(i=>`\`${i}\``).join(', ') || '`N/A`',
|
2020-05-22 22:13:47 +02:00
|
|
|
inline: true
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-24 10:54:33 +02:00
|
|
|
module.exports = ModerationLogsSetting;
|