2020-05-22 22:13:47 +02:00
|
|
|
const { Setting } = require('../../../../interfaces/');
|
2020-08-19 10:26:29 +02:00
|
|
|
const { InfractionResolves } = require('../../../../../util/Constants.js');
|
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-08-04 11:35:28 +02:00
|
|
|
tags: ['log', 'logs', 'logging'],
|
2020-05-24 23:42:28 +02:00
|
|
|
usage: '<method|value> [value..]',
|
2020-05-22 22:13:47 +02:00
|
|
|
resolve: 'GUILD',
|
|
|
|
examples: [
|
2020-08-19 10:26:29 +02:00
|
|
|
'modlog add|remove|set <infraction-type..>',
|
2020-05-24 10:54:33 +02:00
|
|
|
'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,
|
2020-08-16 09:27:49 +02:00
|
|
|
infractions: ['WARN', 'MUTE', 'UNMUTE', 'LOCKDOWN', 'UNLOCKDOWN', 'KICK', 'SOFTBAN', 'BAN', 'UNBAN', 'VCMUTE', 'VCUNMUTE', 'VCKICK', 'VCBAN', 'VCUNBAN']
|
2020-05-22 22:13:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-04 19:59:09 +02:00
|
|
|
async handle(message, params) {
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-07-08 09:59:51 +02:00
|
|
|
const { guild } = message;
|
|
|
|
const setting = guild._settings.moderationLog;
|
2020-08-19 10:26:29 +02:00
|
|
|
|
|
|
|
const result = await this.client.resolver.list(
|
|
|
|
setting.infractions,
|
|
|
|
Object.keys(InfractionResolves),
|
|
|
|
params, this.client.resolver.resolveInfractions.bind(this.client.resolver)
|
|
|
|
);
|
|
|
|
|
|
|
|
if(result) {
|
|
|
|
const { method, list, changed } = result;
|
|
|
|
if(method === 'list') {
|
|
|
|
return {
|
|
|
|
msg: message.format('S_MODERATIONLOG_INFRACTIONSLIST'),
|
|
|
|
error: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(changed.length === 0) {
|
|
|
|
return {
|
|
|
|
msg: message.format('S_MODERATIONLOG_INFRACTIONSFAIL', {
|
|
|
|
method
|
|
|
|
}),
|
|
|
|
error: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
await message.guild._updateSettings({
|
|
|
|
[this.index]: {
|
|
|
|
...setting,
|
|
|
|
infractions: list
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
msg: message.format('S_MODERATIONLOG_INFRACTIONS', {
|
|
|
|
method: message.format('S_MODERATIONLOG_INFRACTIONSMETHODS', { method }, true),
|
|
|
|
plural: changed.length === 1 ? '' : 's',
|
|
|
|
changes: changed
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
const response = await this.resolveMethod(params.map((p) => p.toUpperCase()), Object.keys(InfractionResolves), setting.infractions, this.client.resolver.resolveInfractions.bind(this.client.resolver));
|
|
|
|
|
|
|
|
console.log(response);
|
2020-05-24 00:11:15 +02:00
|
|
|
|
|
|
|
if (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-08-16 09:27:49 +02:00
|
|
|
};
|
2020-05-22 22:13:47 +02:00
|
|
|
|
2020-08-19 10:26:29 +02:00
|
|
|
let index = null;
|
2020-05-24 00:11:15 +02:00
|
|
|
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-08-16 09:27:49 +02:00
|
|
|
};
|
2020-05-25 13:13:34 +02:00
|
|
|
} else if (response.method === 'off') {
|
|
|
|
setting.channel = null;
|
2020-08-16 09:27:49 +02:00
|
|
|
index = 'S_MODERATIONLOG_OFF';
|
2020-05-25 13:13:34 +02:00
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
msg: message.format('ERR_INVALID_METHOD', {
|
|
|
|
method: response.method
|
|
|
|
}),
|
|
|
|
error: true
|
2020-08-16 09:27:49 +02:00
|
|
|
};
|
2020-05-25 13:13:34 +02:00
|
|
|
}
|
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-08-19 10:26:29 +02:00
|
|
|
}
|
|
|
|
*/
|
2020-05-24 00:11:15 +02:00
|
|
|
|
2020-08-19 10:26:29 +02:00
|
|
|
const channel = await guild.resolveChannel(params.join(' '));
|
2020-08-16 09:27:49 +02:00
|
|
|
if (!channel) return {
|
|
|
|
msg: message.format('S_MODERATIONLOG_CHANNEL404', { val: params[0] }),
|
|
|
|
error: true
|
|
|
|
};
|
|
|
|
if(channel.type !== 'text') return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_TYPE', { type: channel.type })
|
|
|
|
};
|
2020-06-19 20:29:54 +02:00
|
|
|
|
2020-08-16 09:27:49 +02:00
|
|
|
const perms = channel.permissionsFor(message.guild.me);
|
|
|
|
const missingPerms = [];
|
|
|
|
if(!perms.has('SEND_MESSAGES')) missingPerms.push('SEND_MESSAGES');
|
|
|
|
if(!perms.has('VIEW_CHANNEL')) missingPerms.push('VIEW_CHANNEL');
|
2020-06-19 20:29:54 +02:00
|
|
|
|
2020-08-16 09:27:49 +02:00
|
|
|
if(missingPerms.length) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
|
|
|
|
};
|
2020-07-04 12:23:10 +02:00
|
|
|
|
2020-08-16 09:27:49 +02:00
|
|
|
await guild._updateSettings({ [this.index]: {
|
|
|
|
...setting,
|
|
|
|
channel: channel.id
|
|
|
|
} }); return {
|
2020-08-19 10:26:29 +02:00
|
|
|
msg: message.format('S_MODERATIONLOG_CHANNEL_SUCCESS', { channel: `<#${channel.id}>` }),
|
2020-08-16 09:27:49 +02:00
|
|
|
error: false
|
|
|
|
};
|
|
|
|
|
2020-05-22 22:13:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-19 15:38:56 +02:00
|
|
|
async 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-08-16 09:27:49 +02:00
|
|
|
name: '》 Status',
|
|
|
|
value: guild.format('SETTING_STATUS', { bool: Boolean(setting.channel) }, true),
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Channel',
|
2020-06-19 15:38:56 +02:00
|
|
|
value: await guild.resolveChannel(setting?.channel) || '`N/A`',
|
2020-05-22 22:13:47 +02:00
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
2020-08-16 09:27:49 +02:00
|
|
|
name: '》 Logged Infractions',
|
|
|
|
value: setting?.infractions.map((i) => `\`${i}\``).join(', ') || '`N/A`'
|
2020-05-22 22:13:47 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-24 10:54:33 +02:00
|
|
|
module.exports = ModerationLogsSetting;
|