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

130 lines
4.5 KiB
JavaScript
Raw Normal View History

2020-05-22 22:13:47 +02:00
const { Setting } = require('../../../../interfaces/');
2020-05-24 00:11:15 +02:00
const CONSTANTS = {
INFRACTIONS: ['NOTE', 'WARN', 'MUTE', 'UNMUTE', 'LOCKDOWN', 'UNLOCKDOWN', 'KICK', 'SOFTBAN', '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',
'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-06-04 19:59:09 +02:00
const setting = message.guild._settings.moderationLog;
const response = await this.resolveMethod(params.map((p) => p.toUpperCase()), 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
}
} 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 = await message.guild.resolveChannel(channel);
2020-05-24 00:11:15 +02:00
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-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(message.guild.me);
2020-06-19 20:29:54 +02:00
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(', ') })
};
await message.guild._updateSettings({ [this.index]: {
...setting,
channel: channel.id,
}}); 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
}
}
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-05-24 10:54:33 +02:00
name: '》Channel',
value: await 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;