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

175 lines
5.9 KiB
JavaScript
Raw Normal View History

2020-05-24 23:41:58 +02:00
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'
],
2020-08-04 11:35:28 +02:00
tags: ['log', 'logs', 'logging'],
2020-05-24 23:41:58 +02:00
usage: '<method|value> [value]',
resolve: 'GUILD',
examples: [
'memberlogs #channel',
'memberlogs join|leave <message>',
'memberlogs reset',
2020-07-11 22:39:05 +02:00
'memberlogs off'
2020-05-24 23:41:58 +02:00
],
default: {
memberLog: {
channel: null,
2020-07-11 22:39:05 +02:00
joinMessage: '{mention} joined the server.',
leaveMessage: '**{tag}** ({id}) left the server.'
2020-05-24 23:41:58 +02:00
}
},
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'
]
}
]
});
}
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)
2020-05-24 23:41:58 +02:00
if (this.client.resolver.resolveBoolean(params[0]) === false) {
2020-05-24 23:41:58 +02:00
setting.channel = null;
2020-05-24 23:41:58 +02:00
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);
2020-05-24 23:41:58 +02:00
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);
2020-05-24 23:41:58 +02:00
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]);
2020-05-24 23:41:58 +02:00
if (!channel) return {
msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: params[0] }),
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(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(', ') })
};
2020-05-24 23:41:58 +02:00
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
2020-05-24 23:41:58 +02:00
};
}
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`',
2020-05-24 23:41:58 +02:00
inline: true
},
{
name: '》 Join Message',
2020-05-24 23:41:58 +02:00
value: `\`${setting?.joinMessage}\`` || '`N/A`',
inline: false
},
{
name: '》 Leave Message',
2020-05-24 23:41:58 +02:00
value: `\`${setting?.leaveMessage}\`` || '`N/A`',
inline: false
}
];
}
}
module.exports = MemberLogsSetting;