automod stuff

This commit is contained in:
Erik 2022-03-27 16:25:04 +03:00
parent 11bd5399bd
commit cc5ed60b11
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 37 additions and 24 deletions

View File

@ -40,6 +40,22 @@ class ModerationManager {
}
actions = {
prune: async (message, argument, targets) => {
const users = targets.map((t) => t.id);
let messages = await message.channel.messages.fetch({
limit: argument.value
});
messages = messages.filter((m) => {
return users.includes(m.author.id) && m.deletable;
});
try {
await message.channel.bulkDelete(messages, true);
} catch (err) { } //eslint-disable-line no-empty
return messages.size;
}
};
async initialize() {
//TODO: Load infractions for non-cached guilds...
@ -189,7 +205,18 @@ class ModerationManager {
}
async handleAutomod(Infraction, info) {
async handleAutomod(Infraction, target, info) {
const response = await this._handleTarget(Infraction, target, info);
const success = !response.error;
if (!success) {
this.client.emit('automodError', response);
return response;
}
if (info.prune) await this.actions.prune({ channel: info.channel }, { value: 100 }, [target]);
return response;
}
@ -310,27 +337,11 @@ class ModerationManager {
async _handleArguments(message, targets) {
const actions = {
prune: async (message, argument, targets) => {
const users = targets.map((t) => t.id);
let messages = await message.channel.messages.fetch({
limit: argument.value
});
messages = messages.filter((m) => {
return users.includes(m.author.id) && m.deletable;
});
try {
await message.channel.bulkDelete(messages, true);
} catch (err) { } //eslint-disable-line no-empty
return messages.size;
}
};
const responses = {};
for (const arg of Object.values(message.arguments)) {
// console.log(arg, targets);
if (actions[arg.name]) {
const action = await actions[arg.name](message, arg, targets);
if (this.actions[arg.name]) {
const action = await this.actions[arg.name](message, arg, targets);
responses[arg.name] = action;
}
}

View File

@ -6,7 +6,6 @@ const { Observer } = require('../../interfaces');
const { BinaryTree, Util, FilterUtil } = require('../../../utilities');
const { FilterPresets } = require('../../../constants');
const { Warn, Mute, Kick, Softban, Ban } = require('../infractions');
const { GuildWrapper } = require('../../client/wrappers');
const CONSTANTS = {
Infractions: {
@ -58,7 +57,7 @@ module.exports = class AutoModeration extends Observer {
this.executing[filterResult.filter].push(member.id);
const InfractionClass = CONSTANTS.Infractions[action.type];
const result = await this.client.moderationManager._handleTarget(InfractionClass, member, {
const result = await this.client.moderationManager.handleAutomod(InfractionClass, member, {
wrapper,
channel,
executor: wrapper.guild.me,
@ -66,15 +65,18 @@ module.exports = class AutoModeration extends Observer {
duration: action.duration,
points: action.points,
expiration: action.expiration,
silent: true, //Won't DM Users.
silent: false, //Won't DM Users.
force: false,
prune: action.prune,
data: {
automoderation: filterResult
}
}).catch(this.logger.error.bind(this.logger));
filterResult.sanctioned = !result.error;
await Util.wait(5000);
this.executing[filterResult.filter].splice(this.executing[filterResult.filter].indexOf(member.id), 1);
return !result.error;
}
@ -261,12 +263,11 @@ module.exports = class AutoModeration extends Observer {
return this.client.rateLimiter.queueDelete(msg.channel, msg).catch(catcher(275));
}
msg.filtered.sanctioned = true;
this.client.rateLimiter.queueDelete(msg.channel, msg).catch(catcher(279));
this.logger.debug(log + '\nSanctioned');
filterResult.filter = 'word';
this._moderate(action, wrapper, channel, member, wrapper.format('W_FILTER_ACTION'), filterResult, message);
await this._moderate(action, wrapper, channel, member, wrapper.format('W_FILTER_ACTION'), filterResult, message);
} else {
this.client.rateLimiter.queueDelete(msg.channel, msg).catch(catcher(269));
@ -331,6 +332,7 @@ module.exports = class AutoModeration extends Observer {
}, [])
};
// TODO: Add action buttons
const sent = await logChannel.send({ embeds: [embed] }).catch((err) => {
this.logger.error('Error in message flag:\n' + err.stack);
});