preliminary invite filter & invite caching
This commit is contained in:
parent
dbf172802d
commit
6ab22a02bf
@ -313,14 +313,76 @@ module.exports = class AutoModeration extends Observer {
|
||||
|
||||
const member = message.member || await guild.members.fetch(author.id).catch();
|
||||
const settings = await guild.settings();
|
||||
const { wordWatcher: setting } = settings;
|
||||
const { words, bypass, ignore, channel: _logChannel } = setting;
|
||||
const { inviteFilter: setting, moderationPoints } = settings;
|
||||
const { bypass, ignore, actions, silent, enabled } = setting;
|
||||
if (!enabled) return;
|
||||
const roles = member?.roles.cache.map((r) => r.id) || [];
|
||||
|
||||
if (!_logChannel || words.length === 0 || roles.some((r) => bypass.includes(r.id)) || ignore.includes(channel.id)) return;
|
||||
if (roles.some((r) => bypass.includes(r.id)) || ignore.includes(channel.id)) return;
|
||||
|
||||
const msg = edited || message;
|
||||
const { content } = msg;
|
||||
|
||||
const reg = /((discord)?\s?\.?\s?gg\s?|discord\.com\/invite)\/\s?(?<code>[a-z0-9]+)/iu;
|
||||
const match = content.match(reg);
|
||||
if (!match) return;
|
||||
|
||||
const result = await guild.checkInvite(match.groups.code);
|
||||
if (!result) { // Doesn't resolve to the origin server
|
||||
|
||||
let action = null;
|
||||
if (actions.length) [action] = actions;
|
||||
|
||||
msg.filtered = {
|
||||
match: match[0],
|
||||
matcher: 'invites'
|
||||
};
|
||||
if (!action) return msg.delete();
|
||||
if (!silent) {
|
||||
const res = await msg.formattedRespond('I_FILTER_DELETE', { params: { user: author.id } });
|
||||
res.delete({ timeout: 10000 });
|
||||
}
|
||||
msg.filtered.sactioned = true;
|
||||
await msg.delete();
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,9 @@ class UtilityHook extends Observer {
|
||||
['guildMemberAdd', this.autorole.bind(this)],
|
||||
['guildMemberAdd', this.automute.bind(this)],
|
||||
['guildMemberAdd', this.stickyRole.bind(this)],
|
||||
['guildMemberRemove', this.storeRoles.bind(this)]
|
||||
['guildMemberRemove', this.storeRoles.bind(this)],
|
||||
['inviteCreate', this.inviteCreate.bind(this)],
|
||||
['inviteDelete', this.inviteDelete.bind(this)]
|
||||
];
|
||||
|
||||
}
|
||||
@ -135,6 +137,26 @@ class UtilityHook extends Observer {
|
||||
.trim();
|
||||
}
|
||||
|
||||
async inviteCreate(invite) {
|
||||
|
||||
const { guild } = invite;
|
||||
if (!guild) return;
|
||||
if (!guild.me.hasPermission('MANAGE_GUILD')) return;
|
||||
if (!guild.invites) guild.invites = await guild.fetchInvites();
|
||||
guild.invites.set(invite.code, invite);
|
||||
|
||||
}
|
||||
|
||||
async inviteDelete(invite) {
|
||||
|
||||
const { guild } = invite;
|
||||
if (!guild) return;
|
||||
if (!guild.me.hasPermission('MANAGE_GUILD')) return;
|
||||
if (!guild.invites) guild.invites = await guild.fetchInvites();
|
||||
guild.invites.delete(invite.code);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UtilityHook;
|
Loading…
Reference in New Issue
Block a user