const { Setting } = require('../../../../interfaces/'); class MemberLogsSetting extends Setting { constructor(client) { super(client, { name: 'memberLog', module: 'moderation', aliases: [ 'memberLogs', 'joinLogs', 'leaveLogs', 'join', 'leave', 'joinMessage', 'leaveMessage', 'joinMsg', 'leaveMsg' ], usage: ' [value]', resolve: 'GUILD', examples: [ 'memberlogs #channel', 'memberlogs join|leave ', 'memberlogs reset', 'memberlogs off', 'memberlogs #channel' ], default: { memberLog: { channel: null, joinMessage: '<@{id}> joined the server.', leaveMessage: '<@{id}> left the server.' } }, arguments: [ { name: 'join', type: 'BOOLEAN', types: ['VERBAL', 'FLAG'], default: true, aliases: [ 'joinmsg', 'joinmessage' ] }, { name: 'leave', type: 'BOOLEAN', types: ['VERBAL', 'FLAG'], default: true, aliases: [ 'leavemsg', 'leavemessage' ] } ] }); this.client = client; } async handle(message, args) { const setting = message.guild._settings[this.index] || this.default[this.index]; const { guild } = message; const { params, parsedArguments } = await this._parseArguments(args, guild); // eslint-disable-next-line init-declarations let index, changes, action; // console.log(args) //console.log(params) //console.log(parsedArguments) if (this.client.resolver.resolveBoolean(params[0]) === false) { setting.channel = null; index = 'S_MEMBERLOGS_TOGGLE'; changes = message.format('ON_OFF_TOGGLE', { toggle: false }, true); } else if (parsedArguments.join || ['join', 'joinmessage', 'joinmsg'].includes(message._settingCaller)) { const response = await this.resolveMethod(params); if (response?.method === 'reset') { setting.joinMessage = this.default.memberLog.joinMessage; index = 'S_MEMBERLOGS_JOIN'; action = message.format('SET_RESET', { set: 'reset' }, true); changes = setting.joinMessage; } else { setting.joinMessage = params.join(' '); index = 'S_MEMBERLOGS_JOIN'; action = message.format('SET_RESET', { set: 'set' }, true); changes = setting.joinMessage; } } else if (parsedArguments.leave || ['leave', 'leavemessage', 'leavemsg'].includes(message._settingCaller)) { const response = await this.resolveMethod(params); if (response?.method === 'reset') { setting.leaveMessage = this.default.memberLog.leaveMessage; index = 'S_MEMBERLOGS_LEAVE'; action = message.format('SET_RESET', { set: 'reset' }, true); changes = setting.joinMessage; } else { setting.leaveMessage = params.join(' '); index = 'S_MEMBERLOGS_LEAVE'; action = message.format('SET_RESET', { set: 'set' }, true); changes = setting.leaveMessage; } } else { const channel = await guild.resolveChannel(params[0]); if (!channel) return { msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: params[0] }), error: true }; if(channel.type !== 'text') return { error: true, msg: message.format('ERR_CHANNEL_TYPE', { type: channel.type }) }; const perms = channel.permissionsFor(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(', ') }) }; index = 'S_MEMBERLOGS_CHANNEL'; changes = channel.name; setting.channel = channel.id; } await message.guild._updateSettings({ [this.index]: setting }); return { msg: message.format(index, { changed: changes || '', action }), error: false }; } async fields(guild) { const setting = guild._settings[this.index]; return [ { name: '》Channel', value: await guild.resolveChannel(setting?.channel) || '`N/A`', inline: true }, { name: '》Join Message', value: `\`${setting?.joinMessage}\`` || '`N/A`', inline: false }, { name: '》Leave Message', value: `\`${setting?.leaveMessage}\`` || '`N/A`', inline: false } ]; } } module.exports = MemberLogsSetting;