galactic-bot/structure/client/components/settings/moderation/ModerationLog.js

174 lines
5.9 KiB
JavaScript
Raw Normal View History

2020-05-22 22:13:47 +02:00
const { Setting } = require('../../../../interfaces/');
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: [
'modlog add|remove|set <infraction-type..>',
2020-05-24 10:54:33 +02:00
'modlog #moderation-log',
'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', '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;
const result = await this.client.resolver.list(
setting.infractions,
Object.keys(InfractionResolves),
2020-11-11 23:58:47 +01:00
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-05-22 22:13:47 +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('`, `') })
};
} 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
const channel = await guild.resolveChannel(params.join(' '));
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
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
if(missingPerms.length) return {
error: true,
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
};
await guild._updateSettings({ [this.index]: {
...setting,
channel: channel.id
} }); return {
msg: message.format('S_MODERATIONLOG_CHANNEL_SUCCESS', { channel: `<#${channel.id}>` }),
error: false
};
2020-05-22 22:13:47 +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 [
{
name: '》 Status',
value: guild.format('SETTING_STATUS', { bool: Boolean(setting.channel) }, true),
inline: true
},
{
name: '》 Channel',
value: await guild.resolveChannel(setting?.channel) || '`N/A`',
2020-05-22 22:13:47 +02:00
inline: true
},
{
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;