From e6ce4e84e12999e31a58714ee2efa712c36784ba Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 1 Sep 2022 13:38:46 +0300 Subject: [PATCH] bugfixes? --- src/structure/client/wrappers/GuildWrapper.js | 2 +- .../components/observers/Automoderation.js | 21 ++++++++++++++----- .../components/observers/UtilityHook.js | 16 +++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index 3724320..d921c38 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -158,7 +158,7 @@ class GuildWrapper { let { settings, _imported } = data; const { defaultConfig } = this; - if (!settings && !_imported?.settings && !_imported?.modlogs) { + if (!settings && !_imported?.settings && !_imported?.modlogs && process.env.NODE_ENV === 'staging') { if (this._importPromise) settings = await this._importPromise; else { this._importPromise = this._attemptDataImport(); diff --git a/src/structure/components/observers/Automoderation.js b/src/structure/components/observers/Automoderation.js index cb89afe..d063db5 100644 --- a/src/structure/components/observers/Automoderation.js +++ b/src/structure/components/observers/Automoderation.js @@ -123,7 +123,10 @@ module.exports = class AutoModeration extends Observer { async filterWords(message, edited) { - const { guild, author, channel, guildWrapper: wrapper } = message; + const { guild, author, guildWrapper: wrapper } = message; + let { channel } = message; + if (channel.partial) channel = await channel.fetch(); + if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); @@ -248,7 +251,9 @@ module.exports = class AutoModeration extends Observer { async flagMessages(message, edited) { - const { guild, author, channel, guildWrapper: wrapper } = message; + const { guild, author, guildWrapper: wrapper } = message; + let { channel } = message; + if (channel.partial) channel = await channel.fetch(); if (!guild || author.bot) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); @@ -420,7 +425,9 @@ module.exports = class AutoModeration extends Observer { async filterLinks(message, edited) { - const { guild, author, channel, guildWrapper: wrapper } = message; + const { guild, author, guildWrapper: wrapper } = message; + let { channel } = message; + if (channel.partial) channel = await channel.fetch(); if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); @@ -546,7 +553,9 @@ module.exports = class AutoModeration extends Observer { async filterInvites(message, edited) { - const { guild, author, channel, guildWrapper: wrapper } = message; + const { guild, author, guildWrapper: wrapper } = message; + let { channel } = message; + if (channel.partial) channel = await channel.fetch(); if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); @@ -604,7 +613,9 @@ module.exports = class AutoModeration extends Observer { async filterMentions(message) { - const { guild, author, channel, guildWrapper: wrapper } = message; + const { guild, author, guildWrapper: wrapper } = message; + let { channel } = message; + if (channel.partial) channel = await channel.fetch(); if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); diff --git a/src/structure/components/observers/UtilityHook.js b/src/structure/components/observers/UtilityHook.js index 1ea74e9..abe53cd 100644 --- a/src/structure/components/observers/UtilityHook.js +++ b/src/structure/components/observers/UtilityHook.js @@ -68,7 +68,7 @@ class UtilityHook extends Observer { if (infraction.data.muteType === 0) { if (!role) return; - await member.roles.add(setting.role, 'automute upon rejoin, type 0'); + await member.roles.add(setting.role, 'automute upon rejoin, type 0').catch(() => null); } else if (infraction.data.muteType === 1) { if (!role) return; @@ -77,10 +77,12 @@ class UtilityHook extends Observer { const managed = roles.find((r) => r.managed); const remove = roles.filter((r) => !r.managed); //Have to do this bs for managed roles -.- - if (managed) { - await member.roles.add(setting.role, 'automute upon rejoin, type 1'); - await member.roles.remove(remove, 'removing excess roles for type 1 mute'); - } else await member.roles.set([role], 'automute upon join, type 1'); + try { + if (managed) { + await member.roles.add(setting.role, 'automute upon rejoin, type 1'); + await member.roles.remove(remove, 'removing excess roles for type 1 mute'); + } else await member.roles.set([role], 'automute upon join, type 1'); + } catch { /* nothing */ } } else if (infraction.data.muteType === 2) { @@ -89,7 +91,7 @@ class UtilityHook extends Observer { const roles = member.roles.cache; const remove = roles.filter((r) => !r.managed); //Have to do this bs for managed roles -.- - await member.roles.remove(remove, 'automute upon join, type 1'); + await member.roles.remove(remove, 'automute upon join, type 1').catch(() => null); } @@ -116,7 +118,7 @@ class UtilityHook extends Observer { const { guildWrapper: guild } = member; const settings = await guild.settings(); const setting = settings.autorole; - if (!setting.enabled) return; + if (!setting.enabled || !setting.roles) return; const me = await guild.resolveMember(this.client.user); if (!me.permissions.has('ManageRoles')) return;