158 lines
5.1 KiB
JavaScript
158 lines
5.1 KiB
JavaScript
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]',
|
|
resolve: 'GUILD',
|
|
examples: [
|
|
'memberlogs #channel',
|
|
'memberlogs join|leave <message>',
|
|
'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 = 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;
|
|
|
|
}
|
|
|
|
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: 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; |