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

103 lines
3.3 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 = {
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'
],
guarded: true,
resolve: 'GUILD',
examples: [
2020-05-24 10:54:33 +02:00
'modlog <add|remove|list> <infraction-type..>',
'modlog #moderation-log',
'modlog reset'
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;
}
async handle(message, args) {
2020-05-24 00:11:15 +02:00
const setting = message.guild._settings.modlogs || this.default.modlogs;
const response = this.resolveMethod(args, CONSTANTS.INFRACTIONS, setting.infractions);
if (response) {
2020-05-22 22:13:47 +02:00
2020-05-24 00:11:15 +02:00
if (args.length < 2 && response.method !== 'list') return {
2020-05-24 10:54:33 +02:00
msg: message.format('S_MODERATIONLOG_ARGS404'),
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-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) {
return [
{
2020-05-24 10:54:33 +02:00
name: '》Channel',
value: guild.resolveChannel(guild._settings[this.index]?.channel) || '`N/A`',
2020-05-22 22:13:47 +02:00
inline: true
},
{
2020-05-24 10:54:33 +02:00
name: '》Logged Infractions',
value: guild._settings[this.index].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;