This commit is contained in:
Erik 2022-08-10 21:08:33 +03:00
parent 5d6c5c5747
commit 252ee2ef4a
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 17 additions and 15 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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));