2020-06-02 12:09:28 +02:00
|
|
|
const { Setting } = require('../../../../interfaces/');
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
const CONSTANTS = {
|
2020-08-16 09:27:49 +02:00
|
|
|
INFRACTIONS: ['WARN', 'MUTE', 'KICK', 'SOFTBAN', 'BAN', 'VCMUTE', 'VCKICK', 'VCBAN']
|
2020-06-09 17:58:54 +02:00
|
|
|
};
|
2020-06-02 12:09:28 +02:00
|
|
|
|
|
|
|
class ModerationPointsSetting extends Setting {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'moderationPoints',
|
|
|
|
module: 'moderation',
|
|
|
|
aliases: [
|
|
|
|
'moderationPoint',
|
|
|
|
'modPoints',
|
|
|
|
'modPoint'
|
|
|
|
],
|
2020-08-31 16:47:37 +02:00
|
|
|
usage: '<action|method> [value]',
|
2020-06-02 12:09:28 +02:00
|
|
|
resolve: 'GUILD',
|
|
|
|
examples: [
|
2020-08-31 16:47:37 +02:00
|
|
|
'modpoints kick points 5',
|
|
|
|
'modpoints warn expire 2 weeks',
|
|
|
|
'modpoints on',
|
|
|
|
'modpoints multiplier on',
|
|
|
|
'modpoints associate nsfw 5'
|
2020-06-02 12:09:28 +02:00
|
|
|
],
|
|
|
|
default: {
|
|
|
|
moderationPoints: {
|
|
|
|
enabled: false,
|
|
|
|
points: {
|
|
|
|
WARN: 0,
|
|
|
|
MUTE: 0,
|
|
|
|
KICK: 0,
|
|
|
|
SOFTBAN: 0,
|
|
|
|
BAN: 0,
|
|
|
|
VCMUTE: 0,
|
|
|
|
VCKICK: 0,
|
|
|
|
VCBAN: 0
|
|
|
|
},
|
|
|
|
expirations: {
|
|
|
|
WARN: 0,
|
|
|
|
KICK: 0,
|
|
|
|
MUTE: 0,
|
|
|
|
SOFTBAN: 0,
|
|
|
|
BAN: 0,
|
|
|
|
VCMUTE: 0,
|
|
|
|
VCKICK: 0,
|
|
|
|
VCBAN: 0
|
|
|
|
},
|
2020-06-09 17:58:54 +02:00
|
|
|
associations: {},
|
|
|
|
multiplier: false //expiration = expiration*points
|
2020-06-02 12:09:28 +02:00
|
|
|
}
|
2020-08-16 09:27:49 +02:00
|
|
|
},
|
|
|
|
archivable: false
|
2020-06-02 12:09:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async handle(message, args) {
|
|
|
|
|
2020-09-01 17:45:43 +02:00
|
|
|
const setting = message.guild._settings[this.index];
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-06-10 16:48:58 +02:00
|
|
|
// eslint-disable-next-line prefer-const
|
2020-06-09 17:58:54 +02:00
|
|
|
let [method, ...params] = args,
|
|
|
|
index = null,
|
|
|
|
langParams = {};
|
|
|
|
method = method.toLowerCase();
|
2020-07-11 22:36:55 +02:00
|
|
|
const { resolver } = this.client;
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-07-11 22:36:55 +02:00
|
|
|
if (resolver.resolveBoolean(method)) {
|
2020-06-09 17:58:54 +02:00
|
|
|
setting.enabled = true;
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_TOGGLE';
|
2020-06-09 17:58:54 +02:00
|
|
|
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: true }, true) };
|
2020-07-11 22:36:55 +02:00
|
|
|
} else if (resolver.resolveBoolean(method) === false) {
|
2020-06-09 17:58:54 +02:00
|
|
|
setting.enabled = false;
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_TOGGLE';
|
2020-06-09 17:58:54 +02:00
|
|
|
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: false }, true) };
|
|
|
|
} else if (method === 'multiplier') {
|
|
|
|
|
|
|
|
const [bool] = params;
|
2020-07-11 22:36:55 +02:00
|
|
|
if (resolver.resolveBoolean(bool)) setting.multiplier = true;
|
|
|
|
else if (resolver.resolveBooeal(bool) === false) setting.multiplier = false;
|
2020-06-09 17:58:54 +02:00
|
|
|
else return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_INVALID_SUBMETHOD', { submethod: bool })
|
|
|
|
};
|
|
|
|
|
|
|
|
} else if (method === 'associate') {
|
|
|
|
|
2020-07-11 22:36:55 +02:00
|
|
|
const { method: submethod, changed } = await resolver.resolveMethod(params, null, Object.keys(setting.associations));
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
if (submethod === 'reset') {
|
|
|
|
setting.associations = {};
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_ASSOCIATE_RESET';
|
2020-06-09 17:58:54 +02:00
|
|
|
} else if (submethod === 'remove') {
|
|
|
|
|
|
|
|
for (const elem of changed) delete setting.associations[elem];
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_REMOVE';
|
2020-06-09 17:58:54 +02:00
|
|
|
langParams = { words: changed.join(', ') };
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let [word, arg] = params;
|
|
|
|
word = word.toLowerCase();
|
|
|
|
const points = parseInt(arg);
|
2020-08-19 10:26:29 +02:00
|
|
|
if (isNaN(points)) return { error: true, msg: message.format('S_MODERATIONPOINTS_NAN', { arg }) };
|
|
|
|
if (points < 0) return { error: true, msg: message.format('S_MODERATIONPOINTS_TOOSMALL', { arg: points }) };
|
|
|
|
if (points > 100) return { error: true, msg: message.format('S_MODERATIONPOINTS_TOOBIG', { arg: points }) };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
setting.associations[word] = points;
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_ASSOCIATE';
|
2020-06-09 17:58:54 +02:00
|
|
|
langParams = { word, points };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-31 16:47:37 +02:00
|
|
|
} else if (resolver.resolveInfraction(method)) { //CONSTANTS.INFRACTIONS.includes(method.toLowerCase())
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let [submethod, value] = params;
|
|
|
|
submethod = submethod.toLowerCase();
|
2020-08-31 16:47:37 +02:00
|
|
|
const infraction = resolver.resolveInfraction(method);
|
|
|
|
if (!CONSTANTS.INFRACTIONS.includes(infraction)) return { error: true, msg: message.format('S_MODERATIONPOINTS_INVALID_TYPE', { infraction }) };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-08-31 16:47:37 +02:00
|
|
|
if (['points', 'point', 'p'].includes(submethod) || !isNaN(parseInt(submethod))) {
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-08-31 16:47:37 +02:00
|
|
|
if (!value) value = submethod;
|
2020-06-09 17:58:54 +02:00
|
|
|
const points = parseInt(value);
|
2020-08-19 10:26:29 +02:00
|
|
|
if (isNaN(points)) return { error: true, msg: message.format('S_MODERATIONPOINTS_NAN', { arg: value }) };
|
|
|
|
if (points < 0) return { error: true, msg: message.format('S_MODERATIONPOINTS_TOOSMALL', { arg: points }) };
|
|
|
|
if (points > 100) return { error: true, msg: message.format('S_MODERATIONPOINTS_TOOBIG', { arg: points }) };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-08-31 16:47:37 +02:00
|
|
|
setting.points[infraction] = points;
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_ASSOCIATE';
|
2020-08-31 16:47:37 +02:00
|
|
|
langParams = { word: infraction, points };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
} else if (['expire', 'expires'].includes(submethod)) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line require-unicode-regexp
|
|
|
|
const timereg = /([0-9]{1,3}\s?[a-z]{1,7})|(0)/i;
|
|
|
|
const { content } = message;
|
|
|
|
|
2020-08-19 10:26:29 +02:00
|
|
|
if (!timereg.test(content)) return { error: true, msg: message.format('S_MODERATIONPOINTS_INVALID_TIMESTRING') };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
const match = content.match(timereg);
|
2020-07-11 22:36:55 +02:00
|
|
|
const time = resolver.resolveTime(match[1]);
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-08-19 10:26:29 +02:00
|
|
|
if (time === null) return { error: true, msg: message.format('S_MODERATIONPOINTS_INVALID_TIMESTRING') };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
2020-08-31 16:47:37 +02:00
|
|
|
setting.expirations[infraction] = time;
|
2020-08-19 10:26:29 +02:00
|
|
|
index = 'S_MODERATIONPOINTS_EXPIRE';
|
2020-08-31 16:47:37 +02:00
|
|
|
langParams = { type: infraction, time: this.client.resolver.timeAgo(time) };
|
2020-06-09 17:58:54 +02:00
|
|
|
|
|
|
|
} else return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_INVALID_SUBMETHOD', { submethod })
|
|
|
|
};
|
|
|
|
|
|
|
|
} else return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_INVALID_METHOD', { method })
|
2020-06-02 12:09:28 +02:00
|
|
|
};
|
|
|
|
|
2020-06-09 17:58:54 +02:00
|
|
|
await message.guild._updateSettings({ [this.index]: setting });
|
|
|
|
return { msg: message.format(index, langParams), error: false };
|
|
|
|
|
2020-06-02 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async fields(guild) {
|
|
|
|
const setting = guild._settings[this.index];
|
2020-06-09 17:58:54 +02:00
|
|
|
return [
|
|
|
|
{
|
2020-08-16 09:27:49 +02:00
|
|
|
name: '》 Status',
|
|
|
|
value: guild.format('SETTING_STATUS', { bool: Boolean(setting?.enabled) }, true),
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Default Points',
|
2020-08-19 10:26:29 +02:00
|
|
|
value: Object.entries(setting.points).map(([key, value]) => `**${key}:** \`${value}\``).join('\n'),
|
|
|
|
inline: true
|
2020-08-16 09:27:49 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Default Expirations',
|
2020-08-19 10:26:29 +02:00
|
|
|
value: Object.entries(setting.expirations).map(([key, value]) => `**${key}:** \`${value ? this.client.resolver.timeAgo(value): 'N/A'}\``).join('\n'),
|
|
|
|
inline: true
|
2020-06-09 17:58:54 +02:00
|
|
|
}
|
2020-06-10 16:48:58 +02:00
|
|
|
];
|
2020-06-02 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ModerationPointsSetting;
|