From 252ee2ef4ac3d438b0fb908e61b0e71d04e5873d Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 10 Aug 2022 21:08:33 +0300 Subject: [PATCH] fixes --- src/structure/client/Resolver.js | 20 +++++++++---------- .../components/observers/AuditLog.js | 11 +++++----- .../components/observers/UtilityHook.js | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/structure/client/Resolver.js b/src/structure/client/Resolver.js index 35d2e17..c2069ec 100644 --- a/src/structure/client/Resolver.js +++ b/src/structure/client/Resolver.js @@ -108,7 +108,7 @@ class Resolver { if ((/<@!?([0-9]{17,21})>/u).test(resolveable)) { - const [, id] = resolveable.match(/<@!?([0-9]{17,21})>/u); + const [, id] = resolveable.toString().match(/<@!?([0-9]{17,21})>/u); const user = await users.fetch(id).catch((err) => { if (err.code === 10013) return false; // this.client.logger.warn(err); return false; @@ -118,7 +118,7 @@ class Resolver { } else if ((/(id:)?([0-9]{17,21})/u).test(resolveable)) { - const [, , id] = resolveable.match(/(id:)?([0-9]{17,21})/u); + const [, , id] = resolveable.toString().match(/(id:)?([0-9]{17,21})/u); const user = await users.fetch(id).catch((err) => { if (err.code === 10013) return false; // this.client.logger.warn(err); return false; @@ -128,7 +128,7 @@ class Resolver { } else if ((/^@?([\S\s]{1,32})#([0-9]{4})/u).test(resolveable)) { - const m = resolveable.match(/^@?([\S\s]{1,32})#([0-9]{4})/u); + const m = resolveable.toString().match(/^@?([\S\s]{1,32})#([0-9]{4})/u); const username = m[1].toLowerCase(); const discrim = m[2].toLowerCase(); const user = users.cache.sort((a, b) => a.username.length - b.username.length) @@ -187,7 +187,7 @@ class Resolver { if ((/<@!?([0-9]{17,21})>/u).test(resolveable)) { - const [, id] = resolveable.match(/<@!?([0-9]{17,21})>/u); + const [, id] = resolveable.toString().match(/<@!?([0-9]{17,21})>/u); const member = await members.fetch(id).catch((err) => { if (err.code === 10007) return false; // this.client.logger.warn(err); return false; @@ -197,7 +197,7 @@ class Resolver { } else if ((/(id:)?([0-9]{17,21})/u).test(resolveable)) { - const [, , id] = resolveable.match(/(id:)?([0-9]{17,21})/u); + const [, , id] = resolveable.toString().match(/(id:)?([0-9]{17,21})/u); const member = await members.fetch(id).catch((err) => { if (err.code === 10007) return false; // this.client.logger.warn(err); return false; @@ -207,7 +207,7 @@ class Resolver { } else if ((/^@?([\S\s]{1,32})#([0-9]{4})/u).test(resolveable)) { - const m = resolveable.match(/^@?([\S\s]{1,32})#([0-9]{4})/u); + const m = resolveable.toString().match(/^@?([\S\s]{1,32})#([0-9]{4})/u); const username = m[1].toLowerCase(); const discrim = m[2].toLowerCase(); const member = members.cache.filter( @@ -218,7 +218,7 @@ class Resolver { } else if ((/^@?([\S\s]{1,32})/u).test(resolveable) && guild && !strict) { - const nickname = resolveable.match(/^@?([\S\s]{1,32})/u)[0].toLowerCase(); + const nickname = resolveable.toString().match(/^@?([\S\s]{1,32})/u)[0].toLowerCase(); const member = members.cache.sort((a, b) => a.user.username.length - b.user.username.length).filter((m) => m && m.user && ((!m.nickname ? false : m.nickname.toLowerCase() === nickname) || (!m.nickname ? false : m.nickname.toLowerCase().includes(nickname)) || @@ -273,7 +273,7 @@ class Resolver { if (id.test(resolveable)) { - const match = resolveable.match(id); + const match = resolveable.toString().match(id); const [, , rId] = match; const role = await roles.fetch(rId).catch(this.client.logger.error); if (role) resolved.push(role); @@ -344,14 +344,14 @@ class Resolver { if (id.test(resolveable)) { - const match = resolveable.match(id); + const match = resolveable.toString().match(id); const [, ch] = match; const channel = await CM.fetch(ch).catch((e) => { }); //eslint-disable-line no-empty, no-empty-function, no-unused-vars if (channel && filter(channel)) resolved.push(channel); } else if (name.test(resolveable)) { - const match = resolveable.match(name); + const match = resolveable.toString().match(name); const ch = match[1].toLowerCase(); const channel = CM.cache.sort((a, b) => a.name.length - b.name.length).filter(filter).filter((c) => { if (!strict) return c.name.toLowerCase().includes(ch); diff --git a/src/structure/components/observers/AuditLog.js b/src/structure/components/observers/AuditLog.js index 725d57f..f116fab 100644 --- a/src/structure/components/observers/AuditLog.js +++ b/src/structure/components/observers/AuditLog.js @@ -56,7 +56,7 @@ class AuditLogObserver extends Observer { const { guildWrapper: wrapper } = member; const settings = await wrapper.settings(); if (!settings.moderation.channel || !settings.moderation.infractions.includes('KICK')) return undefined; //This is checked by the infraction handling, but it may save resources if checked earlier. - const audit = await this._fetchFirstEntry(wrapper, member.user, 'MemberKick'); + const audit = await this._fetchFirstEntry(wrapper, member.id, 'MemberKick'); if (!audit) return undefined; new Infraction(this.client, { type: 'KICK', @@ -151,14 +151,15 @@ class AuditLogObserver extends Observer { const me = await guild.resolveMember(this.client.user); if (!me.permissions.has('ViewAuditLog')) return null; type = AuditLogEvent[type]; - const audit = await guild.fetchAuditLogs({ limit: 1, type }); - if (audit.entries.size === 0) return null; + const audit = await guild.fetchAuditLogs({ limit: 1, type }).catch(() => null); + if (!audit || audit.entries.size === 0) return null; + user = user.id || user; - const entry = audit.entries.filter((e) => e?.target?.id === user.id && + const entry = audit.entries.filter((e) => e?.target?.id === user && subtype ? e.changes.some((e) => e.key === subtype) : true).first(); if (!entry || entry.executor.id === this.client.user.id) return null; - if (entry.target.id !== user.id) return null; + if (entry.target.id !== user) return null; if (entry.action !== type) return null; return entry; diff --git a/src/structure/components/observers/UtilityHook.js b/src/structure/components/observers/UtilityHook.js index 897279b..d362a26 100644 --- a/src/structure/components/observers/UtilityHook.js +++ b/src/structure/components/observers/UtilityHook.js @@ -121,6 +121,7 @@ class UtilityHook extends Observer { if (!me.permissions.has('ManageRoles')) return; const _roles = await guild.resolveRoles(setting.roles); + if (_roles.some((r) => r.position >= me.roles.highest.position)) return; const roles = _roles.map((r) => r.id); await member.roles.add(roles, 'Adding autoroles').catch(this.logger.error.bind(this.logger));