fixes, changed error log to use plain text when missing embed perms

This commit is contained in:
Erik 2022-09-19 22:02:28 +03:00
parent 449a6dc408
commit e28b2f2890
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 25 additions and 12 deletions

View File

@ -306,7 +306,7 @@ class ModerationManager {
if (target instanceof GuildMember) { if (target instanceof GuildMember) {
// The cached member is sometimes outdated, ensure we get the latest member so the perm checks don't fail // The cached member is sometimes outdated, ensure we get the latest member so the perm checks don't fail
// Would help if members had a cached timestamp, might have to change this to work with a wrapper // Would help if members had a cached timestamp, might have to change this to work with a wrapper
target = await guild.members.fetch({ user: target, force: true }); target = await guild.members.fetch({ user: target, force: true }).catch(() => null);
} else if (!(target instanceof User)) { } else if (!(target instanceof User)) {
target = await wrapper.channels.fetch(target.id, { force: true }); target = await wrapper.channels.fetch(target.id, { force: true });
} }

View File

@ -137,7 +137,8 @@ module.exports = class AutoModeration extends Observer {
if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return;
const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; const perms = channel.permissionsFor(this.client.user);
const missing = perms?.missing('ManageMessages') || [];
if (missing.length) { if (missing.length) {
this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'word', permissions: missing }); this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'word', permissions: missing });
return; return;
@ -209,7 +210,7 @@ module.exports = class AutoModeration extends Observer {
log += `\nFilter result: ${inspect(filterResult)}`; log += `\nFilter result: ${inspect(filterResult)}`;
if (!silent && channel.permissionsFor(this.client.user)?.has('SendMessages')) { if (!silent && perms?.has('SendMessages')) {
const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('W_FILTER_DELETE', { user: author.id }), undefined, 'wordFilter').catch(() => null); const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('W_FILTER_DELETE', { user: author.id }), undefined, 'wordFilter').catch(() => null);
//const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } }); //const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } });
//if (res) res.delete({ timeout: 10000 }).catch(catcher(240)); //if (res) res.delete({ timeout: 10000 }).catch(catcher(240));
@ -439,7 +440,8 @@ module.exports = class AutoModeration extends Observer {
if (roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; if (roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return;
const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; const perms = channel.permissionsFor(this.client.user);
const missing = perms?.missing('ManageMessages') || [];
if (missing.length) { if (missing.length) {
this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'link', permissions: missing }); this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'link', permissions: missing });
return; return;
@ -516,7 +518,7 @@ module.exports = class AutoModeration extends Observer {
msg.filtered = filterResult; msg.filtered = filterResult;
filterResult.filter = 'link'; filterResult.filter = 'link';
if (!silent) { if (!silent && perms?.has('SendMessages')) {
const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('L_FILTER_DELETE', { user: author.id }), undefined, 'linkFilter'); const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('L_FILTER_DELETE', { user: author.id }), undefined, 'linkFilter');
//const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } }); //const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } });
//if (res) res.delete({ timeout: 10000 }); //if (res) res.delete({ timeout: 10000 });
@ -566,7 +568,8 @@ module.exports = class AutoModeration extends Observer {
if (roles.some((r) => bypass?.includes(r)) || ignore?.includes(channel.id)) return; if (roles.some((r) => bypass?.includes(r)) || ignore?.includes(channel.id)) return;
const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; const perms = channel.permissionsFor(this.client.user);
const missing = perms?.missing('ManageMessages') || [];
if (missing.length) { if (missing.length) {
this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'invite', permissions: missing }); this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'invite', permissions: missing });
return; return;
@ -594,7 +597,7 @@ module.exports = class AutoModeration extends Observer {
filter: 'invite' filter: 'invite'
}; };
if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg).catch(() => null); //msg.delete(); if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg).catch(() => null); //msg.delete();
if (!silent) { if (!silent && perms?.has('SendMessages')) {
const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter'); const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter');
//if (res) res.delete({ timeout: 10000 }); //if (res) res.delete({ timeout: 10000 });
setTimeout(() => { setTimeout(() => {
@ -626,7 +629,8 @@ module.exports = class AutoModeration extends Observer {
if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return;
const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; const perms = channel.permissionsFor(this.client.user);
const missing = perms?.missing('ManageMessages') || [];
if (missing.length) { if (missing.length) {
this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'mention', permissions: missing }); this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'mention', permissions: missing });
return; return;
@ -646,7 +650,7 @@ module.exports = class AutoModeration extends Observer {
} }
if (ids.length < limit) return; if (ids.length < limit) return;
if (!silent) { if (!silent && perms?.has('SendMessages')) {
const res = await this.client.rateLimiter.limitSend(channel, wrapper.format('M_FILTER_DELETE', { user: author.id }), undefined, 'mentionFilter'); const res = await this.client.rateLimiter.limitSend(channel, wrapper.format('M_FILTER_DELETE', { user: author.id }), undefined, 'mentionFilter');
setTimeout(() => { setTimeout(() => {
res.delete?.().catch(() => { /**/ }); res.delete?.().catch(() => { /**/ });
@ -678,4 +682,8 @@ module.exports = class AutoModeration extends Observer {
} }
async raidProtection(member) {
}
}; };

View File

@ -153,12 +153,17 @@ class ErrorLog extends Observer {
async post(guild, embed, type) { async post(guild, embed, type) {
const settings = await guild.settings(); const settings = await guild.settings();
const { errors } = settings; const { errors } = settings;
// TODO add types to error logging
// eslint-disable-next-line no-unused-vars
const { channel: _channel, types } = errors; const { channel: _channel, types } = errors;
if (!_channel) return; if (!_channel) return;
const channel = await guild.resolveChannel(_channel); const channel = await guild.resolveChannel(_channel);
if (!channel || channel.permissionsFor(guild.me).missing('SendMessages', 'EmbedLinks')) return; const perms = channel.permissionsFor(guild.me);
this.client.rateLimiter.limitSend(channel, { embeds: [embed] }, null, type);
if (!channel || perms.missing('SendMessages').length) return;
if (!perms.missing('EmbedLinks').length) this.client.rateLimiter.limitSend(channel, { content: embed.description });
else this.client.rateLimiter.limitSend(channel, { embeds: [embed] }, null, type);
} }
} }