forked from Galactic/galactic-bot
Merge branch 'master' of https://github.com/GalacticBot/New-GBot
This commit is contained in:
commit
a846a06eea
@ -2,6 +2,7 @@ const { inspect } = require('util');
|
||||
const similarity = require('similarity');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
const { GuildMember } = require('../../../extensions/');
|
||||
const { Observer, BinaryTree } = require('../../../interfaces');
|
||||
const { FilterUtil, FilterPresets, Util } = require('../../../../util');
|
||||
const { Warn, Mute, Kick, Softban, Ban } = require('../../../moderation/infractions');
|
||||
@ -47,8 +48,31 @@ module.exports = class AutoModeration extends Observer {
|
||||
|
||||
}
|
||||
|
||||
_moderate(action, guild, channel, member, moderationPoints, silent, reason, filterResult, message) {
|
||||
this.client.moderationManager.autoModerate({ guild, action, message, reason, silent, data: { filterResult } });
|
||||
async _moderate(action, guild, channel, member, removeme2, silent, reason, filterResult, removeme) {
|
||||
const InfractionClass = CONSTANTS.Infractions[action.type];
|
||||
await this.client.moderationManager._handleTarget(InfractionClass, member, {
|
||||
guild,
|
||||
channel,
|
||||
executor: guild.me,
|
||||
reason,
|
||||
duration: action.duration,
|
||||
points: action.points,
|
||||
expiration: action.expiration,
|
||||
silent: true,
|
||||
force: false,
|
||||
data: {
|
||||
automoderation: {
|
||||
type: 'filler',
|
||||
matched: {
|
||||
type: 'wordfiltertype/explicit/regex/whatever',
|
||||
word: 'whatwasmatched'
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// this.client.moderationManager.autoModerate({ guild, action, message, reason, silent, data: { filterResult } });
|
||||
|
||||
/* this.client.moderationManager.handleInfraction(
|
||||
CONSTANTS.Infractions[action.type],
|
||||
@ -96,12 +120,6 @@ module.exports = class AutoModeration extends Observer {
|
||||
|
||||
if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return;
|
||||
|
||||
if (command?.name === 'settings') {
|
||||
// NOTE: probably needs a more permanent solution
|
||||
const result = await this.client.registry.components.get('inhibitor:permissions').execute(message, message.command);
|
||||
if (!result.error) return;
|
||||
}
|
||||
|
||||
// Which message obj to work with
|
||||
const msg = edited || message;
|
||||
if (!msg.content) return;
|
||||
|
@ -343,7 +343,7 @@ module.exports = class FilterSetting extends Setting {
|
||||
action.type = response.content.toUpperCase();
|
||||
if (['BAN', 'MUTE'].includes(action.type) && !action.duration) return this._editDuration(message, setting, action);
|
||||
|
||||
action.duration = null;
|
||||
action.duration = 0;
|
||||
return action;
|
||||
|
||||
}
|
||||
@ -365,7 +365,7 @@ module.exports = class FilterSetting extends Setting {
|
||||
};
|
||||
|
||||
if (response.content === '0') {
|
||||
action.duration = null;
|
||||
action.duration = 0;
|
||||
} else {
|
||||
const time = resolver.resolveTime(response.content);
|
||||
if (!time) return {
|
||||
|
@ -1,10 +1,9 @@
|
||||
const { stripIndents } = require('common-tags');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { Message } = require('discord.js');
|
||||
const { Console } = require('winston/lib/winston/transports');
|
||||
|
||||
const { Collection, Util, Emojis, Constants } = require('../../util/');
|
||||
const { User, GuildMember } = require('../extensions/');
|
||||
const { Collection, Util, Emojis } = require('../../util/');
|
||||
const { User } = require('../extensions/');
|
||||
const { Warn, Unmute, Mute, Kick, Softban, Unban, Ban } = require('./infractions/');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const Infraction = require('./interfaces/Infraction');
|
||||
@ -86,11 +85,13 @@ class ModerationManager {
|
||||
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,
|
||||
data: info.data,
|
||||
force
|
||||
force,
|
||||
silent
|
||||
});
|
||||
responses.push({
|
||||
escalation: Infraction.type !== response.infraction.type,
|
||||
@ -141,17 +142,18 @@ class ModerationManager {
|
||||
const actions = await this._handleArguments(message, succeededTargets); //eslint-disable-line no-unused-vars
|
||||
|
||||
let string = "";
|
||||
for(const [ , data ] of Object.entries(successes)) {
|
||||
if(silent) continue;
|
||||
const { dictionary, targetType } = data.infraction;
|
||||
const reason = data.escalation ? message.format('INFRACTION_ESCALATIONREASON') : Util.escapeMarkdown(data.infraction.reason);
|
||||
const str = `${Emojis.success} ${message.format('INFRACTION_SUCCESS', {
|
||||
infraction: dictionary.past,
|
||||
targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`,
|
||||
target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '),
|
||||
text: !data.escalation ? ` ${reason.length > 120 ? `for: \`${reason.substring(0, 117)}...\`` : `for: \`${reason}\``}` : ` because \`${reason}\``
|
||||
})}`;
|
||||
data.escalation ? string += str : string = `${str}\n${string}`; //eslint-disable-line
|
||||
if(!silent) {
|
||||
for(const [ , data ] of Object.entries(successes)) {
|
||||
const { dictionary, targetType } = data.infraction;
|
||||
const reason = data.escalation ? message.format('INFRACTION_ESCALATIONREASON') : Util.escapeMarkdown(data.infraction.reason);
|
||||
const str = `${Emojis.success} ${message.format('INFRACTION_SUCCESS', {
|
||||
infraction: dictionary.past,
|
||||
targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`,
|
||||
target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '),
|
||||
text: !data.escalation ? ` ${reason.length > 120 ? `for: \`${reason.substring(0, 117)}...\`` : `for: \`${reason}\``}` : ` because \`${reason}\``
|
||||
})}`;
|
||||
data.escalation ? string += str : string = `${str}\n${string}`; //eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
for(const [ , data ] of Object.entries(fails)) {
|
||||
@ -180,24 +182,24 @@ class ModerationManager {
|
||||
|
||||
async _handleTarget(Infraction, target, info, automod = false) {
|
||||
const { guild, reason, force } = info;
|
||||
const { autoModeration, moderationPoints, silent } = guild._settings;
|
||||
const { autoModeration, moderationPoints } = guild._settings;
|
||||
const { type } = Infraction;
|
||||
|
||||
let points = 0,
|
||||
expiration = 0;
|
||||
if(moderationPoints.enabled) {
|
||||
points = info.arguments?.points?.value || moderationPoints.points[type];
|
||||
expiration = info.arguments?.expiration?.value || moderationPoints.expirations[type];
|
||||
points = info.points || moderationPoints.points[type];
|
||||
expiration = info.expiration || moderationPoints.expirations[type];
|
||||
for(const [ phrase, amount ] of Object.entries(moderationPoints.associations)) {
|
||||
if(reason.toLowerCase().includes(phrase)) points = amount;
|
||||
}
|
||||
}
|
||||
|
||||
const verify = async (infraction, escalated = false) => {
|
||||
|
||||
|
||||
let verification = infraction.verify(info.executor, target, info.channel);
|
||||
if(verification instanceof Promise) verification = await verification;
|
||||
|
||||
|
||||
if(verification.error) return verification;
|
||||
|
||||
if(infraction.targetType === 'USER') {
|
||||
@ -205,7 +207,7 @@ class ModerationManager {
|
||||
const oldPoints = await userTarget.totalPoints(guild);
|
||||
|
||||
const newPoints = oldPoints + infraction.points;
|
||||
if(autoModeration.enabled && points > 0 && !force && !automod && !escalated) {
|
||||
if(autoModeration.enabled && points > 0 && !force && !escalated) {
|
||||
let result = null;
|
||||
for(let [ threshold, action ] of Object.entries(autoModeration.thresholds)) { //eslint-disable-line prefer-const
|
||||
threshold = parseInt(threshold);
|
||||
@ -250,7 +252,7 @@ class ModerationManager {
|
||||
data: info.data,
|
||||
points,
|
||||
expiration,
|
||||
silent: silent || info.arguments.silent
|
||||
silent: info.silent
|
||||
});
|
||||
|
||||
let response = await verify(infraction);
|
||||
@ -270,7 +272,7 @@ class ModerationManager {
|
||||
data: info.data,
|
||||
points,
|
||||
expiration,
|
||||
silent: silent || info.arguments.silent
|
||||
silent: info.silent
|
||||
});
|
||||
response = await verify(escalationInfraction, true);
|
||||
}
|
||||
@ -305,14 +307,12 @@ class ModerationManager {
|
||||
executor: guild.me,
|
||||
arguments: null,
|
||||
reason,
|
||||
duration: duration,
|
||||
duration,
|
||||
data,
|
||||
force,
|
||||
silent
|
||||
});
|
||||
|
||||
console.log(response)
|
||||
|
||||
if (response.error) this.client.logger.debug(`Automod infraction execution failed:\n${JSON.stringify(response)}`);
|
||||
// TODO:
|
||||
// Figure out what we want to do with these errors if anything apart from potentially log them
|
||||
|
@ -33,7 +33,7 @@ class Infraction {
|
||||
this.message = data.message || null;
|
||||
|
||||
this.targetId = data.target ? data.target.id : null;
|
||||
this.target = data.target || [];
|
||||
this.target = data.target || null;
|
||||
|
||||
this.executorId = data.executor ? data.executor.id : null;
|
||||
this.executor = data.executor || null;
|
||||
|
Loading…
Reference in New Issue
Block a user