moderation stuff

This commit is contained in:
Erik 2022-04-05 22:43:47 +03:00
parent 7dc8cab0ee
commit 527d105bce
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -79,35 +79,36 @@ class ModerationManager {
* @return {object|Message} The successfully moderated targets of the response message for failure
* @memberof ModerationManager
*/
async handleInfraction(Infraction, message, info) {
async handleInfraction(Infraction, interaction, info) {
const { targets } = info;
const { targets, args } = info;
const maxTargets = Constant.MaxTargets + message.guild.premium * Constant.MaxTargets;
const maxTargets = Constant.MaxTargets + interaction.guild.premium * Constant.MaxTargets;
if (targets.length > maxTargets) {
return message.respond(stripIndents`${message.format('MODERATIONMANAGER_INFRACTION_MAXTARGETS', {
return interaction.reply(stripIndents`${interaction.format('MODERATIONMANAGER_INFRACTION_MAXTARGETS', {
maxTargets, type: Infraction.targetType
})}
${maxTargets < 40 ? message.format('MODERATIONMANAGER_INFRACTION_MAXTARGETSALT') : ''}`, {
${maxTargets < 40 ? interaction.format('MODERATIONMANAGER_INFRACTION_MAXTARGETSALT') : ''}`, {
emoji: 'failure'
});
}
const silent = Boolean(message.guild._settings.silent || message.arguments.silent);
const force = message.arguments?.force?.value || false;
const silent = Boolean(interaction.guild._settings.silent.enabled || args.silent?.value);
const force = args?.force?.value || false;
const responses = [];
for (const target of targets) {
const response = await this._handleTarget(Infraction, target, {
message,
guild: message.guild,
channel: message.channel,
executor: message.member,
arguments: message.arguments,
points: message.arguments?.points?.value,
expiration: message.arguments?.expiration?.value,
reason: info.reason,
duration: info.duration,
interaction,
guild: interaction.guild,
wrapper: interaction.guild,
channel: interaction.channel,
executor: interaction.member,
arguments: args,
points: args.points?.value,
expiration: args.expiration?.value,
reason: args.reason?.value,
duration: args.duration?.value,
data: info.data,
force,
silent
@ -125,7 +126,7 @@ class ModerationManager {
const fatals = failed.filter((f) => f.fatal);
if (fatals.length > 0) {
const [error] = fatals;
return message.respond(message.format(error.reason), { emoji: 'failure' });
return interaction.reply(interaction.format(error.reason), { emoji: 'failure' });
}
const successes = {};
@ -135,10 +136,10 @@ class ModerationManager {
if (!response.error) {
if (!silent) {
if (successes[type]) {
successes[type].targets.push(target.display);
successes[type].targets.push(target.tag || target.name);
} else {
successes[type] = {
targets: [target.display],
targets: [target.tag || target.name],
infraction: response.infraction,
escalation: response.escalation
};
@ -146,10 +147,10 @@ class ModerationManager {
}
} else {
if (fails[type]) {
fails[type].targets.push(target.display);
fails[type].targets.push(target.tag || target.name);
} else {
fails[type] = {
targets: [target.display],
targets: [target.tag || target.name],
infraction: response.infraction,
reason: response.reason
};
@ -158,16 +159,16 @@ class ModerationManager {
}
const succeededTargets = succeeded.map((s) => s.infraction.target);
const actions = await this._handleArguments(message, succeededTargets); //eslint-disable-line no-unused-vars
const actions = await this._handleArguments(interaction, succeededTargets, args); //eslint-disable-line no-unused-vars
let string = "";
if (!silent) {
for (const [, data] of Object.entries(successes)) {
const { dictionary, targetType } = data.infraction;
const reason = data.escalation ?
message.format('INFRACTION_ESCALATIONREASON') :
interaction.format('INFRACTION_ESCALATIONREASON') :
Util.escapeMarkdown(data.infraction.reason);
const str = `${Emojis.success} ${message.format('INFRACTION_SUCCESS', {
const str = `${Emojis.success} ${interaction.format('INFRACTION_SUCCESS', {
infraction: dictionary.past,
targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`,
target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '),
@ -183,25 +184,26 @@ class ModerationManager {
for (const [, data] of Object.entries(fails)) {
const { dictionary, targetType } = data.infraction;
const str = `${Emojis.failure} ${message.format('INFRACTION_FAIL', {
const str = `${Emojis.failure} ${interaction.format('INFRACTION_FAIL', {
infraction: dictionary.present,
targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`,
target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '),
reason: message.format(data.reason)
reason: interaction.format(data.reason)
})}`;
(!data.escalation && !success) //eslint-disable-line
? string = `${str}\n${string}`
: string += str;
}
if (success && silent) { //Delete message if silent.
try {
await message.delete();
} catch (e) { } //eslint-disable-line no-empty
}
// if (success && silent) { //Delete message if silent.
// try {
// await interaction.delete();
// } catch (e) { } //eslint-disable-line no-empty
// }
if (string) message.respond(string);
return succeeded;
//if (string) interaction.reply(string);
// return succeeded;
return string.length ? string : null;
}
@ -222,6 +224,7 @@ class ModerationManager {
async _handleTarget(Infraction, target, info) {
// wrapper: guildWrapper
const { reason, force, wrapper } = info;
const { automod, modpoints } = wrapper._settings;
const { type } = Infraction;
@ -284,9 +287,9 @@ class ModerationManager {
};
const infraction = new Infraction(this.client, {
target,
target: targetWrapper,
type,
message: info.message || null,
interaction: info.interaction || null,
arguments: info.arguments,
guild: info.wrapper,
channel: info.channel,
@ -305,7 +308,7 @@ class ModerationManager {
if (Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[response.escalation.type]) {
const escalationClass = Constant.Infractions[response.escalation.type];
const escalationInfraction = new escalationClass(this.client, {
target,
target: targetWrapper,
message: info.message || null,
arguments: info.arguments,
type: escalationClass.type,
@ -335,13 +338,13 @@ class ModerationManager {
}
async _handleArguments(message, targets) {
async _handleArguments(interaction, targets, args) {
const responses = {};
for (const arg of Object.values(message.arguments)) {
for (const arg of Object.values(args)) {
// console.log(arg, targets);
if (this.actions[arg.name]) {
const action = await this.actions[arg.name](message, arg, targets);
const action = await this.actions[arg.name](interaction, arg, targets);
responses[arg.name] = action;
}
}