forked from Galactic/galactic-bot
modpoints setting
This commit is contained in:
parent
b23bab68fa
commit
31e6e8bd11
@ -90,7 +90,8 @@ class MessageLogsSetting extends Setting {
|
||||
|
||||
} else {
|
||||
return {
|
||||
msg: message.format('ERR_INVALID_METHOD', { method })
|
||||
msg: message.format('ERR_INVALID_METHOD', { method }),
|
||||
error: true
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,9 @@
|
||||
const { Setting } = require('../../../../interfaces/');
|
||||
const timestring = require('timestring');
|
||||
|
||||
const CONSTANTS = {
|
||||
INFRACTIONS: ['note', 'warn', 'mute', 'unmute', 'lockdown', 'unlockdown', 'kick', 'ban', 'unban', 'vcmute', 'vcunmute', 'vckick', 'vcban', 'vcunban', 'prune', 'slowmode', 'dehoist', 'addrole', 'removerole', 'nickname']
|
||||
};
|
||||
|
||||
class ModerationPointsSetting extends Setting {
|
||||
|
||||
@ -40,8 +45,8 @@ class ModerationPointsSetting extends Setting {
|
||||
VCKICK: 0,
|
||||
VCBAN: 0
|
||||
},
|
||||
assocations: {},
|
||||
multiplier: false //points*expiration = new expiration..?
|
||||
associations: {},
|
||||
multiplier: false //expiration = expiration*points
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -52,16 +57,131 @@ class ModerationPointsSetting extends Setting {
|
||||
|
||||
async handle(message, args) {
|
||||
|
||||
//to do
|
||||
return {
|
||||
msg: 'fuck off',
|
||||
error: false
|
||||
const setting = message.guild._settings[this.index] || this.default[this.index];
|
||||
|
||||
let [method, ...params] = args,
|
||||
index = null,
|
||||
langParams = {};
|
||||
method = method.toLowerCase();
|
||||
|
||||
if (this.client.resolver.resolveBoolean(method)) {
|
||||
setting.enabled = true;
|
||||
index = 'S_MODPOINTS_TOGGLE';
|
||||
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: true }, true) };
|
||||
} else if (this.client.resolver.resolveBoolean(method) === false) {
|
||||
setting.enabled = false;
|
||||
index = 'S_MODPOINTS_TOGGLE';
|
||||
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: false }, true) };
|
||||
} else if (method === 'multiplier') {
|
||||
|
||||
const [bool] = params;
|
||||
if (this.client.resolver.resolveBoolean(bool)) setting.multiplier = true;
|
||||
else if (this.client.resolver.resolveBooeal(bool) === false) setting.multiplier = false;
|
||||
else return {
|
||||
error: true,
|
||||
msg: message.format('ERR_INVALID_SUBMETHOD', { submethod: bool })
|
||||
};
|
||||
|
||||
} else if (method === 'associate') {
|
||||
|
||||
const { method: submethod, changed } = this.client.resolver.resolveMethod(params, null, Object.keys(setting.associations));
|
||||
|
||||
if (submethod === 'reset') {
|
||||
setting.associations = {};
|
||||
index = 'S_MODPOINTS_ASSOCIATE_RESET';
|
||||
} else if (submethod === 'remove') {
|
||||
|
||||
for (const elem of changed) delete setting.associations[elem];
|
||||
index = 'S_MODPOINTS_REMOVE';
|
||||
langParams = { words: changed.join(', ') };
|
||||
|
||||
} else {
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [word, arg] = params;
|
||||
word = word.toLowerCase();
|
||||
const points = parseInt(arg);
|
||||
if (isNaN(points)) return { error: true, msg: message.format('S_MODPOINTS_NAN', { arg }) };
|
||||
if (points < 0) return { error: true, msg: message.format('S_MODPOINTS_TOOSMALL', { arg: points }) };
|
||||
if (points > 100) return { error: true, msg: message.format('S_MODPOINTS_TOOBIG', { arg: points }) };
|
||||
|
||||
setting.associations[word] = points;
|
||||
index = 'S_MODPOINTS_ASSOCIATE';
|
||||
langParams = { word, points };
|
||||
|
||||
}
|
||||
|
||||
} else if (CONSTANTS.INFRACTIONS.includes(method)) {
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [submethod, value] = params;
|
||||
submethod = submethod.toLowerCase();
|
||||
|
||||
if (['points', 'point', 'p'].includes(submethod)) {
|
||||
|
||||
const points = parseInt(value);
|
||||
if (isNaN(points)) return { error: true, msg: message.format('S_MODPOINTS_NAN', { arg: value }) };
|
||||
if (points < 0) return { error: true, msg: message.format('S_MODPOINTS_TOOSMALL', { arg: points }) };
|
||||
if (points > 100) return { error: true, msg: message.format('S_MODPOINTS_TOOBIG', { arg: points }) };
|
||||
|
||||
setting.points[method] = points;
|
||||
index = 'S_MODPOINTS_ASSOCIATE';
|
||||
langParams = { word: method, points };
|
||||
|
||||
} 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;
|
||||
|
||||
if (!timereg.test(content)) return { error: true, msg: message.format('S_MODPOINTS_INVALID_TIMESTRING') };
|
||||
|
||||
const match = content.match(timereg);
|
||||
let time = null;
|
||||
try {
|
||||
time = timestring(match[1]);
|
||||
} catch (e) {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
if (time === null) return { error: true, msg: message.format('S_MODPOINTS_INVALID_TIMESTRING') };
|
||||
|
||||
setting.expirations[method.toUpperCase()] = time;
|
||||
index = 'S_MODPOINTS_EXPIRE';
|
||||
langParams = { type: method, time: this.client.resolver.timeAgo(time) };
|
||||
|
||||
} else return {
|
||||
error: true,
|
||||
msg: message.format('ERR_INVALID_SUBMETHOD', { submethod })
|
||||
};
|
||||
|
||||
} else return {
|
||||
error: true,
|
||||
msg: message.format('ERR_INVALID_METHOD', { method })
|
||||
};
|
||||
|
||||
await message.guild._updateSettings({ [this.index]: setting });
|
||||
return { msg: message.format(index, langParams), error: false };
|
||||
|
||||
}
|
||||
|
||||
async fields(guild) {
|
||||
const setting = guild._settings[this.index];
|
||||
return [
|
||||
{
|
||||
name: '》Enabled',
|
||||
value: setting.enabled,
|
||||
inline: false
|
||||
}, {
|
||||
name: '》Points',
|
||||
value: Object.keys(setting.points).map(key => `\`${key}: ${setting.points[key]}\``).join(', '),
|
||||
inline: false
|
||||
}, {
|
||||
name: '》Expirations',
|
||||
value: Object.keys(setting.expirations).map(key => `\`${key}: ${this.client.resolver.timeAgo(setting.expirations[key])}\``).join(', '),
|
||||
inline: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user