diff --git a/structure/Registry.js b/structure/Registry.js index 44755de..438eddf 100644 --- a/structure/Registry.js +++ b/structure/Registry.js @@ -14,7 +14,7 @@ class Registry { find(name) { - return this.commands.find((c) => c.name === name || c.aliases?.includes(name)); + return this.commands.find((c) => c.name === name.toLowerCase() || c.aliases?.includes(name.toLowerCase())); } diff --git a/structure/Resolver.js b/structure/Resolver.js index 5cca711..c9a2b2b 100644 --- a/structure/Resolver.js +++ b/structure/Resolver.js @@ -72,6 +72,70 @@ class Resolver { } + /** + * Resolve multiple channels + * + * @param {Array} [resolveables=[]] an array of channel resolveables (name, id) + * @param {Guild} guild the guild in which to look for channels + * @param {Boolean} [strict=false] whether or not partial names are resolved + * @param {Function} [filter=()] filter the resolving channels + * @returns {Promise> || Promise} an array of guild channels or false if none were resolved + * @memberof Resolver + */ + async resolveChannels(resolveables = [], strict = false, guild = null, filter = () => true) { + + if (typeof resolveables === 'string') resolveables = [resolveables]; + if (resolveables.length === 0) return false; + if (!guild) return false; + const CM = guild.channels; + const resolved = []; + + for (const resolveable of resolveables) { + const channel = CM.resolve(resolveable); + if (channel && filter(channel)) { + resolved.push(channel); + continue; + } + + const name = /^#?([a-z0-9\-_0]+)/iu; + const id = /^?/iu; + + if (id.test(resolveable)) { + const match = resolveable.match(id); + const [, ch] = match; + + const channel = await this.client.channels.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 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); + return c.name.toLowerCase() === ch; + }).first(); + + if (channel) resolved.push(channel); + + } + + } + + return resolved.length > 0 ? resolved : false; + + } + + async resolveChannel(resolveable, strict, guild, filter) { + + if (!resolveable) return false; + if (resolveable instanceof Array) throw new Error('Resolveable cannot be of type Array, use resolveChannels for resolving arrays of channels'); + const result = await this.resolveChannels([resolveable], strict, guild, filter); + return result ? result[0] : false; + + } + } module.exports = Resolver; \ No newline at end of file diff --git a/structure/commands/Eval.js b/structure/commands/Eval.js index 634ee2f..ba29b46 100644 --- a/structure/commands/Eval.js +++ b/structure/commands/Eval.js @@ -14,6 +14,7 @@ class Eval extends Command { async execute(message, { clean }) { + if (!this.client._options.evalAccess.includes(message.author.id)) return; const { guild, author, member, client, channel } = message; //eslint-disable-line no-unused-vars try { diff --git a/structure/commands/Markread.js b/structure/commands/Markread.js index fce7c19..1e85615 100644 --- a/structure/commands/Markread.js +++ b/structure/commands/Markread.js @@ -8,9 +8,9 @@ class Markread extends Command { }); } - async execute(message) { + async execute(message, { args }) { - return this.client.modmail.markread(message); + return this.client.modmail.markread(message, args); } diff --git a/structure/commands/Modmail.js b/structure/commands/Modmail.js index 05deef4..82d700a 100644 --- a/structure/commands/Modmail.js +++ b/structure/commands/Modmail.js @@ -25,7 +25,7 @@ class Modmail extends Command { first = second; } - const user = await this.client.resolveUser(first); + const user = await this.client.resolveUser(first, true); if (!user) return { error: true, msg: 'Failed to resolve user'