const { Setting } = require('../../../../interfaces'); const { InfractionResolves } = require('../../../../../util/Constants.js'); class ModerationLogsSetting extends Setting { constructor(client) { super(client, { name: 'moderationLog', module: 'logging', aliases: [ 'moderationLogs', 'modLog', 'modLogs' ], tags: ['log', 'logs', 'logging'], usage: ' [value..]', resolve: 'GUILD', examples: [ 'modlog add|remove|set ', 'modlog #moderation-log', 'modlog reset', 'modlog off' ], default: { moderationLog: { channel: null, infractions: ['WARN', 'MUTE', 'UNMUTE', 'LOCKDOWN', 'UNLOCKDOWN', 'KICK', 'SOFTBAN', 'BAN', 'UNBAN', 'VCMUTE', 'VCUNMUTE', 'VCKICK', 'VCBAN', 'VCUNBAN'] } } }); } async handle(message, params) { const { guild } = message; const setting = guild._settings.moderationLog; 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', types: changed.join('`, `') }) }; } /* 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); if (response) { if (params.length < 2 && response.method !== 'list') return { msg: message.format('MISSING_ARGS'), error: true }; let index = null; if (response.method === 'add') { setting.infractions = response.result; index = 'S_MODERATIONLOG_ADD'; } else if (response.method === 'remove') { setting.infractions = response.result; index = 'S_MODERATIONLOG_REMOVE'; } else if (response.method === 'list') { return { 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 }; } 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' }) }; } */ 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 }) }; 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'); 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 }; } async fields(guild) { const setting = guild._settings[this.index]; 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`', inline: true }, { name: '》 Logged Infractions', value: setting?.infractions.map((i) => `\`${i}\``).join(', ') || '`N/A`' } ]; } } module.exports = ModerationLogsSetting;