clean up and rate limiting

This commit is contained in:
Erik 2021-05-06 01:09:45 +03:00
parent ccef862e4b
commit 9f9d68214e

View File

@ -234,8 +234,9 @@ module.exports = class AutoModeration extends Observer {
msg.filtered = filterResult; msg.filtered = filterResult;
log += `\nFilter result: ${inspect(filterResult)}`; log += `\nFilter result: ${inspect(filterResult)}`;
if (!silent) { if (!silent) {
const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } }); const res = await this.client.rateLimiter.limitSend(msg.channel, msg.format('W_FILTER_DELETE', { user: author.id }), undefined, 'wordFilter');
res.delete({ timeout: 10000 }); //const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } });
if (res) res.delete({ timeout: 10000 });
} }
// 6. Automated actions // 6. Automated actions
@ -253,49 +254,18 @@ module.exports = class AutoModeration extends Observer {
if (!action) { if (!action) {
this.client.logger.debug(log); this.client.logger.debug(log);
return msg.delete(); this.client.rateLimiter.queueDelete(msg.channel, msg);
} }
msg.filtered.sanctioned = true; msg.filtered.sanctioned = true;
msg.delete(); this.client.rateLimiter.queueDelete(msg.channel, msg);
this.client.logger.debug(log + '\nSanctioned'); this.client.logger.debug(log + '\nSanctioned');
// NOTE: this will have to be changed whenever the moderation manager is finished and properly supports sth like this // NOTE: this will have to be changed whenever the moderation manager is finished and properly supports sth like this
this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('W_FILTER_ACTION'), filterResult, message); this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('W_FILTER_ACTION'), filterResult, message);
// this.client.moderationManager.handleInfraction(
// CONSTANTS.Infractions[action.type],
// { // Hacky patched together message object with just the required stuff for modmanager to work
// guild,
// member: guild.me,
// channel,
// arguments: {
// force: {
// value: action.force
// },
// points: {
// value: action.points || moderationPoints.points[action.type]
// },
// expiration: {
// value: action.expiration || moderationPoints.expirations[action.type]
// },
// silent: setting.silent
// },
// format: guild.format.bind(guild),
// // eslint-disable-next-line no-empty-function
// respond: () => { }
// },
// {
// targets: [member],
// reason: msg.format('W_FILTER_ACTION'),
// duration: action.duration,
// data: {
// filterResult
// }
// }
// );
} else { } else {
msg.delete(); this.client.rateLimiter.queueDelete(msg.channel, msg);
this.client.logger.debug(log); this.client.logger.debug(log);
} }
@ -406,8 +376,9 @@ module.exports = class AutoModeration extends Observer {
if (!remove) return; if (!remove) return;
msg.filtered = filterResult; msg.filtered = filterResult;
if (!silent) { if (!silent) {
const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } }); const res = await this.client.rateLimiter.limitSend(msg.channel, msg.format('L_FILTER_DELETE', { user: author.id }), undefined, 'linkFilter');
res.delete({ timeout: 10000 }); //const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } });
if (res) res.delete({ timeout: 10000 });
} }
if (actions.length) { if (actions.length) {
@ -425,11 +396,12 @@ module.exports = class AutoModeration extends Observer {
if (!action) return msg.delete(); if (!action) return msg.delete();
msg.filtered.sactioned = true; msg.filtered.sactioned = true;
msg.delete(); this.client.rateLimiter.queueDelete(msg.channel, msg);
//msg.delete();
this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('L_FILTER_ACTION'), filterResult, message); this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('L_FILTER_ACTION'), filterResult, message);
} else msg.delete(); } else this.client.rateLimiter.queueDelete(msg.channel, msg); //msg.delete();
} }
@ -464,51 +436,15 @@ module.exports = class AutoModeration extends Observer {
match: match[0], match: match[0],
matcher: 'invites' matcher: 'invites'
}; };
if (!action) return msg.delete(); if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg); //msg.delete();
if (!silent) { if (!silent) {
const res = await msg.formattedRespond('I_FILTER_DELETE', { params: { user: author.id } }); const res = await this.client.rateLimiter.limitSend(msg.channel, msg.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter');
res.delete({ timeout: 10000 }); if (res) res.delete({ timeout: 10000 });
} }
msg.filtered.sactioned = true; msg.filtered.sactioned = true;
msg.delete(); this.client.rateLimiter.queueDelete(msg.channel, msg);
this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('I_FILTER_ACTION'), { filtered: msg.filtered }, message); this._moderate(action, guild, channel, member, moderationPoints, silent, msg.format('I_FILTER_ACTION'), { filtered: msg.filtered }, message);
// NOTE: this will have to be changed whenever the moderation manager is finished and properly supports sth like this
// this.client.moderationManager.handleInfraction(
// CONSTANTS.Infractions[action.type],
// {
// guild,
// member: guild.me,
// channel,
// arguments: {
// force: {
// value: action.force
// },
// points: {
// value: action.points || moderationPoints.points[action.type]
// },
// expiration: {
// value: action.expiration || moderationPoints.expirations[action.type]
// },
// silent: setting.silent//,
// //prune: {
// // name: 'prune',
// // value: 50
// //}
// },
// format: guild.format.bind(guild),
// // eslint-disable-next-line no-empty-function
// respond: () => {}
// },
// {
// targets: [member],
// reason: msg.format('I_FILTER_ACTION'),
// duration: action.duration,
// data: {
// filtered: msg.filtered
// }
// }
// );
} }