forked from Galactic/galactic-bot
104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
const { Setting } = require('../../../../interfaces/');
|
|
|
|
const CONSTANTS = {
|
|
INFRACTIONS: ['note', 'warn', 'mute', 'unmute', 'lockdown', 'lockdownend', 'kick', 'ban', 'unban', 'vcmute', 'vcunmute', 'vckick', 'vcban', 'vcunban', 'prune', 'slowmode', 'dehoist', 'addrole', 'removerole', 'nickname']
|
|
};
|
|
|
|
class Modlogs extends Setting {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'moderationLog',
|
|
module: 'moderation',
|
|
aliases: [
|
|
'moderationLogs',
|
|
'modLog',
|
|
'modLogs'
|
|
],
|
|
guarded: true,
|
|
resolve: 'GUILD',
|
|
index: 'modlogs',
|
|
examples: [
|
|
'modlogs <add|remove|list> <infraction-type..>',
|
|
'modlogs #moderation-log',
|
|
'modlogs reset'
|
|
],
|
|
default: {
|
|
modlogs: {
|
|
channel: undefined,
|
|
infractions: ['warn','mute','unmute','lockdown','lockdownend','kick','ban','unban','vcmute','vcunmute','vckick','vcban','vcunban']
|
|
}
|
|
}
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async handle(message, args) {
|
|
|
|
const setting = message.guild._settings.modlogs || this.default.modlogs;
|
|
const response = this.resolveMethod(args, CONSTANTS.INFRACTIONS, setting.infractions);
|
|
|
|
if (response) {
|
|
|
|
if (args.length < 2 && response.method !== 'list') return {
|
|
msg: message.format('S_MODLOGS_ARGS404'),
|
|
error: true
|
|
}
|
|
|
|
let index;
|
|
if (response.method === 'add') {
|
|
setting.infractions = response.result;
|
|
index = 'S_MODLOGS_ADD';
|
|
} else if (response.method === 'remove') {
|
|
setting.infractions = response.result;
|
|
index = 'S_MODLOGS_REMOVE';
|
|
} else if (response.method === 'list') {
|
|
return {
|
|
msg: message.format('S_MODLOGS_LIST', { list: setting.infractions.join('`, `') })
|
|
}
|
|
}
|
|
|
|
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' }) };
|
|
|
|
} else {
|
|
|
|
let [channel] = params;
|
|
|
|
channel = message.guild.resolveChannel(channel);
|
|
if (!channel) return {
|
|
msg: message.format('S_MODLOGS_CHANNEL404', { val: params[0] }),
|
|
error: true
|
|
};
|
|
|
|
setting.channel = channel.id;
|
|
await message.guild._updateSettings({ [this.index]: setting }); return {
|
|
msg: message.format('S_MODLOGS_CHANNEL_SUCCESS', { channel: channel.name }),
|
|
error: false
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fields(guild) {
|
|
return [
|
|
{
|
|
name: 'Channel',
|
|
value: guild.resolveChannel(guild._settings[this.index]?.channel) || 'N/A',
|
|
inline: true
|
|
},
|
|
{
|
|
name: 'Enabled infractions',
|
|
value: guild._settings[this.index]?.infractions.join(', ') || 'N/A',
|
|
inline: true
|
|
}
|
|
];
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Modlogs; |