member logs

This commit is contained in:
Erik 2020-05-25 00:41:58 +03:00
parent 54be30cc19
commit 90beb35393

View File

@ -0,0 +1,171 @@
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: '<method|value> [value]',
guarded: true,
resolve: 'GUILD',
examples: [
'memberlogs #channel',
'memberlogs join|leave <message>',
'memberlogs reset',
'memberlogs on|off',
'memberlogs #channel'
],
default: {
memberLog: {
channel: null,
joinMessage: '<@{id}> joined the server.',
leaveMessage: '<@{id}> left the server.',
enabled: false
}
},
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])) {
setting.enabled = setting.channel && true;
index = 'S_MEMBERLOGS_TOGGLE';
changes = message.format('ON_OFF_TOGGLE', { toggle: true }, true);
} else if (this.client.resolver.resolveBoolean(params[0]) === false) {
setting.enabled = false;
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 = 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 = 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 = guild.resolveChannel(params[0]);
if (!channel) return {
msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: params[0] }),
error: true
};
index = 'S_MEMBERLOGS_CHANNEL';
changes = channel.name;
setting.channel = channel.id;
setting.enabled = true;
}
await message.guild._updateSettings({ [this.index]: setting });
return {
msg: message.format(index, { changed: changes || '', action: message.format(action) })
};
}
async fields(guild) {
const setting = guild._settings[this.index];
return [
{
name: '》Enabled',
value: setting?.enabled || false,
inline: true
},
{
name: '》Channel',
value: 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;